forked from kaitai-io/kaitai_struct_csharp_runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '6-nullable-t-for-optional-fields-are-call' into 'master'
Resolve "`Nullable<T>` for optional fields are call" Closes kaitai-io#6 See merge request marta/kaitai_struct_csharp_runtime!14
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Kaitai | ||
{ | ||
public struct ImplicitNullable<T> where T : struct | ||
{ | ||
public bool HasValue { get { return this._value.HasValue; } } | ||
public T Value { get { return this._value.Value; } } | ||
|
||
public ImplicitNullable(T value) : this() { this._value = value; } | ||
public ImplicitNullable(T? value) : this() { this._value = value; } | ||
|
||
public static implicit operator ImplicitNullable<T>(T value) { return new ImplicitNullable<T>(value); } | ||
public static implicit operator ImplicitNullable<T>(T? value) { return new ImplicitNullable<T>(value); } | ||
|
||
public static implicit operator T(ImplicitNullable<T> value) { return value._value ?? default(T); } | ||
public static implicit operator T?(ImplicitNullable<T> value) { return value._value; } | ||
|
||
private T? _value { get; set; } | ||
|
||
// Should define other Nullable<T> members, especially | ||
// Equals and GetHashCode to avoid boxing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters