|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by the StronglyTypedId source generator |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | +#pragma warning disable 1591 // publicly visible type or member must be documented |
| 11 | + |
| 12 | +namespace MyContracts.V1 |
| 13 | +{ |
| 14 | + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] |
| 15 | + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] |
| 16 | + readonly partial struct MyId : System.IComparable<MyId>, System.IEquatable<MyId> |
| 17 | + { |
| 18 | + public System.Guid Value { get; } |
| 19 | + |
| 20 | + public MyId(System.Guid value) |
| 21 | + { |
| 22 | + Value = value; |
| 23 | + } |
| 24 | + |
| 25 | + public static MyId New() => new MyId(System.Guid.NewGuid()); |
| 26 | + public static readonly MyId Empty = new MyId(System.Guid.Empty); |
| 27 | + |
| 28 | + public bool Equals(MyId other) => this.Value.Equals(other.Value); |
| 29 | + public override bool Equals(object obj) |
| 30 | + { |
| 31 | + if (ReferenceEquals(null, obj)) return false; |
| 32 | + return obj is MyId other && Equals(other); |
| 33 | + } |
| 34 | + |
| 35 | + public override int GetHashCode() => Value.GetHashCode(); |
| 36 | + |
| 37 | + public override string ToString() => Value.ToString(); |
| 38 | + public static bool operator ==(MyId a, MyId b) => a.Equals(b); |
| 39 | + public static bool operator !=(MyId a, MyId b) => !(a == b); |
| 40 | + public int CompareTo(MyId other) => Value.CompareTo(other.Value); |
| 41 | + |
| 42 | + class MyIdTypeConverter : System.ComponentModel.TypeConverter |
| 43 | + { |
| 44 | + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) |
| 45 | + { |
| 46 | + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); |
| 47 | + } |
| 48 | + |
| 49 | + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) |
| 50 | + { |
| 51 | + return value switch |
| 52 | + { |
| 53 | + System.Guid guidValue => new MyId(guidValue), |
| 54 | + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), |
| 55 | + _ => base.ConvertFrom(context, culture, value), |
| 56 | + }; |
| 57 | + } |
| 58 | + |
| 59 | + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) |
| 60 | + { |
| 61 | + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); |
| 62 | + } |
| 63 | + |
| 64 | + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) |
| 65 | + { |
| 66 | + if (value is MyId idValue) |
| 67 | + { |
| 68 | + if (destinationType == typeof(System.Guid)) |
| 69 | + { |
| 70 | + return idValue.Value; |
| 71 | + } |
| 72 | + |
| 73 | + if (destinationType == typeof(string)) |
| 74 | + { |
| 75 | + return idValue.Value.ToString(); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return base.ConvertTo(context, culture, value, destinationType); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter |
| 84 | + { |
| 85 | + public override bool CanConvert(System.Type objectType) |
| 86 | + { |
| 87 | + return objectType == typeof(MyId); |
| 88 | + } |
| 89 | + |
| 90 | + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) |
| 91 | + { |
| 92 | + var id = (MyId)value; |
| 93 | + serializer.Serialize(writer, id.Value); |
| 94 | + } |
| 95 | + |
| 96 | + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) |
| 97 | + { |
| 98 | + var guid = serializer.Deserialize<System.Guid?>(reader); |
| 99 | + return guid.HasValue ? new MyId(guid.Value) : null; |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +//------------------------------------------------------------------------------ |
| 106 | +// <auto-generated> |
| 107 | +// This code was generated by the StronglyTypedId source generator |
| 108 | +// |
| 109 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 110 | +// the code is regenerated. |
| 111 | +// </auto-generated> |
| 112 | +//------------------------------------------------------------------------------ |
| 113 | + |
| 114 | +#pragma warning disable 1591 // publicly visible type or member must be documented |
| 115 | + |
| 116 | +namespace MyContracts.V2 |
| 117 | +{ |
| 118 | + [Newtonsoft.Json.JsonConverter(typeof(MyIdNewtonsoftJsonConverter))] |
| 119 | + [System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))] |
| 120 | + readonly partial struct MyId : System.IComparable<MyId>, System.IEquatable<MyId> |
| 121 | + { |
| 122 | + public System.Guid Value { get; } |
| 123 | + |
| 124 | + public MyId(System.Guid value) |
| 125 | + { |
| 126 | + Value = value; |
| 127 | + } |
| 128 | + |
| 129 | + public static MyId New() => new MyId(System.Guid.NewGuid()); |
| 130 | + public static readonly MyId Empty = new MyId(System.Guid.Empty); |
| 131 | + |
| 132 | + public bool Equals(MyId other) => this.Value.Equals(other.Value); |
| 133 | + public override bool Equals(object obj) |
| 134 | + { |
| 135 | + if (ReferenceEquals(null, obj)) return false; |
| 136 | + return obj is MyId other && Equals(other); |
| 137 | + } |
| 138 | + |
| 139 | + public override int GetHashCode() => Value.GetHashCode(); |
| 140 | + |
| 141 | + public override string ToString() => Value.ToString(); |
| 142 | + public static bool operator ==(MyId a, MyId b) => a.Equals(b); |
| 143 | + public static bool operator !=(MyId a, MyId b) => !(a == b); |
| 144 | + public int CompareTo(MyId other) => Value.CompareTo(other.Value); |
| 145 | + |
| 146 | + class MyIdTypeConverter : System.ComponentModel.TypeConverter |
| 147 | + { |
| 148 | + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) |
| 149 | + { |
| 150 | + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); |
| 151 | + } |
| 152 | + |
| 153 | + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) |
| 154 | + { |
| 155 | + return value switch |
| 156 | + { |
| 157 | + System.Guid guidValue => new MyId(guidValue), |
| 158 | + string stringValue when !string.IsNullOrEmpty(stringValue) && System.Guid.TryParse(stringValue, out var result) => new MyId(result), |
| 159 | + _ => base.ConvertFrom(context, culture, value), |
| 160 | + }; |
| 161 | + } |
| 162 | + |
| 163 | + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType) |
| 164 | + { |
| 165 | + return sourceType == typeof(System.Guid) || sourceType == typeof(string) || base.CanConvertTo(context, sourceType); |
| 166 | + } |
| 167 | + |
| 168 | + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) |
| 169 | + { |
| 170 | + if (value is MyId idValue) |
| 171 | + { |
| 172 | + if (destinationType == typeof(System.Guid)) |
| 173 | + { |
| 174 | + return idValue.Value; |
| 175 | + } |
| 176 | + |
| 177 | + if (destinationType == typeof(string)) |
| 178 | + { |
| 179 | + return idValue.Value.ToString(); |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + return base.ConvertTo(context, culture, value, destinationType); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + class MyIdNewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter |
| 188 | + { |
| 189 | + public override bool CanConvert(System.Type objectType) |
| 190 | + { |
| 191 | + return objectType == typeof(MyId); |
| 192 | + } |
| 193 | + |
| 194 | + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) |
| 195 | + { |
| 196 | + var id = (MyId)value; |
| 197 | + serializer.Serialize(writer, id.Value); |
| 198 | + } |
| 199 | + |
| 200 | + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) |
| 201 | + { |
| 202 | + var guid = serializer.Deserialize<System.Guid?>(reader); |
| 203 | + return guid.HasValue ? new MyId(guid.Value) : null; |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments