diff --git a/src/Intellenum/Templates/AnyOtherType/AnyOtherType_SystemTextJsonConverter.cs b/src/Intellenum/Templates/AnyOtherType/AnyOtherType_SystemTextJsonConverter.cs index be67da08..33e5884b 100644 --- a/src/Intellenum/Templates/AnyOtherType/AnyOtherType_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/AnyOtherType/AnyOtherType_SystemTextJsonConverter.cs @@ -11,4 +11,17 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + var primitive = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, options); + return VOTYPE.Deserialize(primitive); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(global::System.Text.Json.JsonSerializer.Serialize(value.Value)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Boolean/Boolean_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Boolean/Boolean_SystemTextJsonConverter.cs index 6ffcfb9e..25955aea 100644 --- a/src/Intellenum/Templates/Boolean/Boolean_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Boolean/Boolean_SystemTextJsonConverter.cs @@ -10,4 +10,16 @@ public override void Write(global::System.Text.Json.Utf8JsonWriter writer, VOTYP { writer.WriteBooleanValue(value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(bool.Parse(reader.GetString())); + } + + public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString()); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Byte/Byte_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Byte/Byte_SystemTextJsonConverter.cs index 4a764af1..0c817b09 100644 --- a/src/Intellenum/Templates/Byte/Byte_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Byte/Byte_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(global::System.Text.Json.Utf8JsonWriter writer, VOTYP __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Byte.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(global::System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Char/Char_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Char/Char_SystemTextJsonConverter.cs index 47cf0041..a76517b2 100644 --- a/src/Intellenum/Templates/Char/Char_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Char/Char_SystemTextJsonConverter.cs @@ -12,4 +12,18 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value.ToString()); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + var s = reader.GetString(); + + return VOTYPE.Deserialize(s[0]); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString()); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/DateOnly/DateOnly_SystemTextJsonConverter.cs b/src/Intellenum/Templates/DateOnly/DateOnly_SystemTextJsonConverter.cs index 37cfd072..5589a996 100644 --- a/src/Intellenum/Templates/DateOnly/DateOnly_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/DateOnly/DateOnly_SystemTextJsonConverter.cs @@ -23,6 +23,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value.ToString("yyyy-MM-dd", global::System.Globalization.CultureInfo.InvariantCulture)); } + + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return new VOTYPE(global::System.DateOnly.ParseExact(reader.GetString(), "yyyy-MM-dd", global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString("yyyy-MM-dd", global::System.Globalization.CultureInfo.InvariantCulture)); + } } #endif diff --git a/src/Intellenum/Templates/DateTime/DateTime_SystemTextJsonConverter.cs b/src/Intellenum/Templates/DateTime/DateTime_SystemTextJsonConverter.cs index ca747e6a..41ecfc48 100644 --- a/src/Intellenum/Templates/DateTime/DateTime_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/DateTime/DateTime_SystemTextJsonConverter.cs @@ -10,4 +10,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.DateTime.ParseExact(reader.GetString(), "O", global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString("O")); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/DateTimeOffset/DateTimeOffset_SystemTextJsonConverter.cs b/src/Intellenum/Templates/DateTimeOffset/DateTimeOffset_SystemTextJsonConverter.cs index 3f1c23b8..bdf32efb 100644 --- a/src/Intellenum/Templates/DateTimeOffset/DateTimeOffset_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/DateTimeOffset/DateTimeOffset_SystemTextJsonConverter.cs @@ -10,4 +10,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.DateTimeOffset.ParseExact(reader.GetString(), "O", global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString("O")); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Decimal/Decimal_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Decimal/Decimal_SystemTextJsonConverter.cs index ad26053d..23ec679a 100644 --- a/src/Intellenum/Templates/Decimal/Decimal_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Decimal/Decimal_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Decimal.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Double/Double_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Double/Double_SystemTextJsonConverter.cs index 7cf2ec2d..40164658 100644 --- a/src/Intellenum/Templates/Double/Double_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Double/Double_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Double.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_DapperTypeHandler.cs b/src/Intellenum/Templates/Float/Float_DapperTypeHandler.cs deleted file mode 100644 index 0838c13f..00000000 --- a/src/Intellenum/Templates/Float/Float_DapperTypeHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ - - public class DapperTypeHandler : global::Dapper.SqlMapper.TypeHandler - { - public override void SetValue(global::System.Data.IDbDataParameter parameter, VOTYPE value) - { - parameter.DbType = global::System.Data.DbType.Single; - parameter.Value = value.Value; - } - - public override VOTYPE Parse(object value) - { - return value switch - { - global::System.Single floatValue => VOTYPE.Deserialize(intValue), - global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Single.TryParse(stringValue, out var result) => VOTYPE.Deserialize(result), - _ => throw new global::System.InvalidCastException($"Unable to cast object of type {value.GetType()} to VOTYPE"), - }; - } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_EfCoreValueConverter.cs b/src/Intellenum/Templates/Float/Float_EfCoreValueConverter.cs deleted file mode 100644 index 6c5b95ed..00000000 --- a/src/Intellenum/Templates/Float/Float_EfCoreValueConverter.cs +++ /dev/null @@ -1,11 +0,0 @@ - - public class EfCoreValueConverter : global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter - { - public EfCoreValueConverter() : this(null) { } - public EfCoreValueConverter(global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints mappingHints = null) - : base( - vo => vo.Value, - value => VOTYPE.Deserialize(value), - mappingHints - ) { } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_LinqToDbValueConverter.cs b/src/Intellenum/Templates/Float/Float_LinqToDbValueConverter.cs deleted file mode 100644 index 78687822..00000000 --- a/src/Intellenum/Templates/Float/Float_LinqToDbValueConverter.cs +++ /dev/null @@ -1,10 +0,0 @@ - - public class LinqToDbValueConverter : global::LinqToDB.Common.ValueConverter - { - public LinqToDbValueConverter() - : base( - v => v.Value, - p => VOTYPE.Deserialize(p), - handlesNulls: false) - { } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_NewtonsoftJsonConverter.cs b/src/Intellenum/Templates/Float/Float_NewtonsoftJsonConverter.cs deleted file mode 100644 index 51858943..00000000 --- a/src/Intellenum/Templates/Float/Float_NewtonsoftJsonConverter.cs +++ /dev/null @@ -1,20 +0,0 @@ - - class VOTYPENewtonsoftJsonConverter : Newtonsoft.Json.JsonConverter - { - public override bool CanConvert(System.Type objectType) - { - return objectType == typeof(VOTYPE); - } - - public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - var id = (VOTYPE)value; - serializer.Serialize(writer, id.Value); - } - - public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - var result = serializer.Deserialize(reader); - return result.HasValue ? VOTYPE.Deserialize(result.Value) : null; - } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Float/Float_SystemTextJsonConverter.cs deleted file mode 100644 index f895f7b1..00000000 --- a/src/Intellenum/Templates/Float/Float_SystemTextJsonConverter.cs +++ /dev/null @@ -1,15 +0,0 @@ - - class VOTYPESystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter - { - public override VOTYPE Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) - { -__NORMAL__ return VOTYPE.Deserialize(reader.GetFloat()); -__STRING__ return VOTYPE.Deserialize(global::System.Float.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); - } - - public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) - { -__NORMAL__ writer.WriteNumberValue(value.Value); -__STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); - } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Float/Float_TypeConverter.cs b/src/Intellenum/Templates/Float/Float_TypeConverter.cs deleted file mode 100644 index ad84d813..00000000 --- a/src/Intellenum/Templates/Float/Float_TypeConverter.cs +++ /dev/null @@ -1,41 +0,0 @@ - - class VOTYPETypeConverter : global::System.ComponentModel.TypeConverter - { - public override global::System.Boolean CanConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) - { - return sourceType == typeof(global::System.Single) || sourceType == typeof(global::System.String) || base.CanConvertFrom(context, sourceType); - } - - public override global::System.Object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value) - { - return value switch - { - global::System.Single floatValue => VOTYPE.Deserialize(floatValue), - global::System.String stringValue when !global::System.String.IsNullOrEmpty(stringValue) && global::System.Single.TryParse(stringValue,NumberStyles.Float | NumberStyles.AllowThousands, culture.NumberFormat, out var result) => VOTYPE.Deserialize(result), - _ => base.ConvertFrom(context, culture, value), - }; - } - - public override bool CanConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Type sourceType) - { - return sourceType == typeof(global::System.Single) || sourceType == typeof(global::System.String) || base.CanConvertTo(context, sourceType); - } - - public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::System.Object value, global::System.Type destinationType) - { - if (value is VOTYPE idValue) - { - if (destinationType == typeof(global::System.Single)) - { - return idValue.Value; - } - - if (destinationType == typeof(global::System.String)) - { - return idValue.Value.ToString(); - } - } - - return base.ConvertTo(context, culture, value, destinationType); - } - } \ No newline at end of file diff --git a/src/Intellenum/Templates/Guid/Guid_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Guid/Guid_SystemTextJsonConverter.cs index 2c7d0fa3..9179031e 100644 --- a/src/Intellenum/Templates/Guid/Guid_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Guid/Guid_SystemTextJsonConverter.cs @@ -10,4 +10,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(System.Guid.Parse(reader.GetString())); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString()); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Int/Int_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Int/Int_SystemTextJsonConverter.cs index ced75abf..a045d828 100644 --- a/src/Intellenum/Templates/Int/Int_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Int/Int_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Long/Long_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Long/Long_SystemTextJsonConverter.cs index 0a104d91..8ca0e8c5 100644 --- a/src/Intellenum/Templates/Long/Long_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Long/Long_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Int64.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Short/Short_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Short/Short_SystemTextJsonConverter.cs index ab4eb85e..e9a254b4 100644 --- a/src/Intellenum/Templates/Short/Short_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Short/Short_SystemTextJsonConverter.cs @@ -12,4 +12,15 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Int16.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/Single/Single_SystemTextJsonConverter.cs b/src/Intellenum/Templates/Single/Single_SystemTextJsonConverter.cs index 8c0aee38..491d0e38 100644 --- a/src/Intellenum/Templates/Single/Single_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/Single/Single_SystemTextJsonConverter.cs @@ -12,4 +12,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, __NORMAL__ writer.WriteNumberValue(value.Value); __STRING__ writer.WriteStringValue(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(global::System.Single.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/String/String_SystemTextJsonConverter.cs b/src/Intellenum/Templates/String/String_SystemTextJsonConverter.cs index 203904ad..407fb759 100644 --- a/src/Intellenum/Templates/String/String_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/String/String_SystemTextJsonConverter.cs @@ -10,4 +10,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value); } + +#if NET6_0_OR_GREATER + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return VOTYPE.Deserialize(reader.GetString()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value); + } +#endif } \ No newline at end of file diff --git a/src/Intellenum/Templates/TimeOnly/TimeOnly_SystemTextJsonConverter.cs b/src/Intellenum/Templates/TimeOnly/TimeOnly_SystemTextJsonConverter.cs index dfa518fe..bf450997 100644 --- a/src/Intellenum/Templates/TimeOnly/TimeOnly_SystemTextJsonConverter.cs +++ b/src/Intellenum/Templates/TimeOnly/TimeOnly_SystemTextJsonConverter.cs @@ -23,6 +23,16 @@ public override void Write(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, { writer.WriteStringValue(value.Value.ToString("o", global::System.Globalization.CultureInfo.InvariantCulture)); } + + public override VOTYPE ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return new VOTYPE(global::System.TimeOnly.Parse(reader.GetString(), global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, VOTYPE value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString("o", global::System.Globalization.CultureInfo.InvariantCulture)); + } } #endif diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Bool.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Bool.cs new file mode 100644 index 00000000..145d7e02 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Bool.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(bool))] +[Member("Manager", true)] +[Member("Operator", false)] +public partial class EmployeeTypeBool +{ +} + +public class Bool +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeBool.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeBool.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeBool.Manager); + d2.Should().ContainKey(EmployeeTypeBool.Operator); + + d2[EmployeeTypeBool.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeBool.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Byte.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Byte.cs new file mode 100644 index 00000000..a151319e --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Byte.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(byte))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeByte +{ +} + +public class Byte +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeByte.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeByte.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeByte.Manager); + d2.Should().ContainKey(EmployeeTypeByte.Operator); + + d2[EmployeeTypeByte.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeByte.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Char.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Char.cs new file mode 100644 index 00000000..d25275ea --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Char.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(char))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeChar +{ +} + +public class Char +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeChar.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeChar.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeChar.Manager); + d2.Should().ContainKey(EmployeeTypeChar.Operator); + + d2[EmployeeTypeChar.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeChar.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateOnly.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateOnly.cs new file mode 100644 index 00000000..80299cc8 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateOnly.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(DateOnly))] +public partial class DateOnlyEnum +{ + public static readonly DateOnlyEnum Manager = new(new DateOnly(2020, 12, 13)); + public static readonly DateOnlyEnum Operator = new(new DateOnly(2023, 12, 13)); +} + +public class DateOnlyTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { DateOnlyEnum.Manager, new List { new Employee("John Smith", 30) } }, + { DateOnlyEnum.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(DateOnlyEnum.Manager); + d2.Should().ContainKey(DateOnlyEnum.Operator); + + d2[DateOnlyEnum.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[DateOnlyEnum.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTime.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTime.cs new file mode 100644 index 00000000..4c772638 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTime.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(DateTime))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeDateTime +{ +} + +public class DateTimeTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeDateTime.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeDateTime.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeDateTime.Manager); + d2.Should().ContainKey(EmployeeTypeDateTime.Operator); + + d2[EmployeeTypeDateTime.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeDateTime.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTimeOffset.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTimeOffset.cs new file mode 100644 index 00000000..49662ad4 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/DateTimeOffset.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(DateTimeOffset))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeDateTimeOffset +{ +} + +public class DateTimeOffsetTests +{ + [Fact] + public void can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeDateTimeOffset.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeDateTimeOffset.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeDateTimeOffset.Manager); + d2.Should().ContainKey(EmployeeTypeDateTimeOffset.Operator); + + d2[EmployeeTypeDateTimeOffset.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeDateTimeOffset.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Decimal.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Decimal.cs new file mode 100644 index 00000000..b94f5a9d --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Decimal.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(decimal))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeDecimal +{ +} + +public class DecimalTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeDecimal.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeDecimal.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeDecimal.Manager); + d2.Should().ContainKey(EmployeeTypeDecimal.Operator); + + d2[EmployeeTypeDecimal.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeDecimal.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Double.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Double.cs new file mode 100644 index 00000000..38fa526c --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Double.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(double))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeDouble +{ +} + +public class DoubleTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeDouble.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeDouble.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeDouble.Manager); + d2.Should().ContainKey(EmployeeTypeDouble.Operator); + + d2[EmployeeTypeDouble.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeDouble.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Employee.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Employee.cs new file mode 100644 index 00000000..45e4719d --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Employee.cs @@ -0,0 +1,5 @@ +#nullable disable +namespace ConsumerTests.EnumAsDictionaryKeyTests +{ + public record Employee(string Name, int Age); +} \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Guid.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Guid.cs new file mode 100644 index 00000000..0ea38233 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Guid.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(Guid))] +public partial class EmployeeTypeGuid +{ + public static readonly EmployeeTypeGuid Manager = new(Guid.Parse("00000000-0000-0000-0000-000000000001")); + public static readonly EmployeeTypeGuid Operator = new(Guid.Parse("00000000-0000-0000-0000-000000000002")); +} + +public class GuidTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeGuid.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeGuid.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeGuid.Manager); + d2.Should().ContainKey(EmployeeTypeGuid.Operator); + + d2[EmployeeTypeGuid.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeGuid.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Int.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Int.cs new file mode 100644 index 00000000..1e265038 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Int.cs @@ -0,0 +1,41 @@ +#if NET6_0_OR_GREATER + +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + + +[Intellenum] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeInt +{ +} + +public class IntTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeInt.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeInt.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeInt.Manager); + d2.Should().ContainKey(EmployeeTypeInt.Operator); + + d2[EmployeeTypeInt.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeInt.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Long.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Long.cs new file mode 100644 index 00000000..acb0f314 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Long.cs @@ -0,0 +1,40 @@ +#if NET6_0_OR_GREATER + +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(long))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeLong +{ +} + +public class LongTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeLong.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeLong.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeLong.Manager); + d2.Should().ContainKey(EmployeeTypeLong.Operator); + + d2[EmployeeTypeLong.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeLong.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Short.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Short.cs new file mode 100644 index 00000000..38fe30da --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Short.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(short))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeShort +{ +} + +public class ShortTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeShort.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeShort.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeShort.Manager); + d2.Should().ContainKey(EmployeeTypeShort.Operator); + + d2[EmployeeTypeShort.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeShort.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/Single.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Single.cs new file mode 100644 index 00000000..9455682e --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/Single.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(Single))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeSingle +{ +} + +public class SingleTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeSingle.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeSingle.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeSingle.Manager); + d2.Should().ContainKey(EmployeeTypeSingle.Operator); + + d2[EmployeeTypeSingle.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeSingle.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/String.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/String.cs new file mode 100644 index 00000000..4eb56dc2 --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/String.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(string))] +[Member("Manager", 1)] +[Member("Operator", 2)] +public partial class EmployeeTypeString +{ +} + +public class StringTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeString.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeString.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeString.Manager); + d2.Should().ContainKey(EmployeeTypeString.Operator); + + d2[EmployeeTypeString.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeString.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ConsumerTests/EnumAsDictionaryKeyTests/TimeOnly.cs b/tests/ConsumerTests/EnumAsDictionaryKeyTests/TimeOnly.cs new file mode 100644 index 00000000..7214d46d --- /dev/null +++ b/tests/ConsumerTests/EnumAsDictionaryKeyTests/TimeOnly.cs @@ -0,0 +1,39 @@ +#if NET6_0_OR_GREATER +#nullable disable + +using System.Text.Json; +using Intellenum.Tests.Types; + +namespace ConsumerTests.EnumAsDictionaryKeyTests; + +[Intellenum(typeof(TimeOnly))] +public partial class EmployeeTypeTimeOnly +{ + public static readonly EmployeeTypeTimeOnly Manager = new(new TimeOnly(12, 13, 59)); + public static readonly EmployeeTypeTimeOnly Operator = new(new TimeOnly(14, 30, 59)); +} + +public class TimeOnlyTests +{ + [Fact] + public void int_can_serialize_intellenum_as_key_of_dictionary() + { + Dictionary> d = new() + { + { EmployeeTypeTimeOnly.Manager, new List { new Employee("John Smith", 30) } }, + { EmployeeTypeTimeOnly.Operator, new List { new Employee("Dave Angel", 42) } } + }; + + var json = JsonSerializer.Serialize(d); + + var d2 = JsonSerializer.Deserialize>>(json); + + d2.Should().ContainKey(EmployeeTypeTimeOnly.Manager); + d2.Should().ContainKey(EmployeeTypeTimeOnly.Operator); + + d2[EmployeeTypeTimeOnly.Manager].Should().Contain(new Employee("John Smith", 30)); + d2[EmployeeTypeTimeOnly.Operator].Should().Contain(new Employee("Dave Angel", 42)); + } +} + +#endif \ No newline at end of file diff --git a/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.int_created_successfully.verified.txt b/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.int_created_successfully.verified.txt index 93ad57a8..59ee8fd8 100644 --- a/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.int_created_successfully.verified.txt +++ b/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.int_created_successfully.verified.txt @@ -352,6 +352,18 @@ yield return Diamond; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(global::System.Int32.Parse(reader.GetString(), global::System.Globalization.NumberStyles.Any, global::System.Globalization.CultureInfo.InvariantCulture)); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value.ToString(global::System.Globalization.CultureInfo.InvariantCulture)); + } +#endif } diff --git a/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.string_created_successfully.verified.txt b/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.string_created_successfully.verified.txt index 6fe638bd..ce00ff91 100644 --- a/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.string_created_successfully.verified.txt +++ b/tests/ScratchSnapshotTests/snapshots/snap-v7.0/GeneralTests.string_created_successfully.verified.txt @@ -360,6 +360,18 @@ yield return Diamond; { writer.WriteStringValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetString()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WritePropertyName(value.Value); + } +#endif } diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt index a60a74fa..fa2459fc 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt @@ -365,6 +365,18 @@ yield return @void; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override @class ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return @class.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, @class value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -426,8 +438,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -446,8 +457,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -466,8 +476,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -486,8 +495,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.No_namespace.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.No_namespace.verified.txt index d45aa2ca..6ac158d6 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.No_namespace.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.No_namespace.verified.txt @@ -350,6 +350,18 @@ yield return Diamond; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -411,8 +423,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -431,8 +442,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -451,8 +461,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -471,8 +480,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt index 05a9cfe0..b21860d4 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt @@ -352,6 +352,18 @@ yield return Diamond; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -413,8 +425,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -433,8 +444,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -453,8 +463,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -473,8 +482,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Produces_instances.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Produces_instances.verified.txt index 67d3d688..66934e3e 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Produces_instances.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v6.0/GeneralTests.Produces_instances.verified.txt @@ -384,6 +384,18 @@ yield return Legacy; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -445,8 +457,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -465,8 +476,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -485,8 +495,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -505,8 +514,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt index 602eafb7..9a7b619b 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Namespace_names_can_have_reserved_keywords.verified.txt @@ -365,6 +365,18 @@ yield return @void; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override @class ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return @class.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, @class value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -426,8 +438,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -446,8 +457,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -466,8 +476,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -486,8 +495,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -506,8 +514,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -526,8 +533,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.No_namespace.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.No_namespace.verified.txt index b51e9b70..4e405cb6 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.No_namespace.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.No_namespace.verified.txt @@ -350,6 +350,18 @@ yield return Diamond; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -411,8 +423,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -431,8 +442,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -451,8 +461,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -471,8 +480,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -491,8 +499,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -511,8 +518,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt index 79c52d7f..fb081682 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Partial_partial_class_created_successfully.verified.txt @@ -352,6 +352,18 @@ yield return Diamond; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -413,8 +425,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -433,8 +444,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -453,8 +463,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -473,8 +482,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -493,8 +501,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -513,8 +520,7 @@ yield return Diamond; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Produces_instances.verified.txt b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Produces_instances.verified.txt index 16081f69..9fdeffe2 100644 --- a/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Produces_instances.verified.txt +++ b/tests/SnapshotTests/GeneralStuff/snapshots/snap-v7.0/GeneralTests.Produces_instances.verified.txt @@ -384,6 +384,18 @@ yield return Legacy; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -445,8 +457,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -465,8 +476,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -485,8 +495,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -505,8 +514,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -525,8 +533,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -545,8 +552,7 @@ yield return Legacy; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.Namespace_names_can_have_reserved_keywords.verified.txt b/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.Namespace_names_can_have_reserved_keywords.verified.txt index 1a766aec..3b1b9573 100644 --- a/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.Namespace_names_can_have_reserved_keywords.verified.txt +++ b/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.Namespace_names_can_have_reserved_keywords.verified.txt @@ -352,6 +352,18 @@ yield return @void; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override @class ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return @class.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, @class value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -413,8 +425,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -433,8 +444,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -453,8 +463,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -473,8 +482,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -493,8 +501,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -513,8 +520,7 @@ yield return @void; #endif out @class result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; diff --git a/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.No_namespace.verified.txt b/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.No_namespace.verified.txt index dc8419ed..b8f70a9c 100644 --- a/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.No_namespace.verified.txt +++ b/tests/SnapshotTests/snapshots/snap-v7.0/GenericAttributeTests.No_namespace.verified.txt @@ -337,6 +337,18 @@ yield return Gold; { writer.WriteNumberValue(value.Value); } + +#if NET6_0_OR_GREATER + public override CustomerType ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) + { + return CustomerType.Deserialize(reader.GetInt32()); + } + + public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, CustomerType value, global::System.Text.Json.JsonSerializerOptions options) + { + writer.WriteNumberValue(value.Value); + } +#endif } @@ -398,8 +410,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -418,8 +429,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -438,8 +448,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -458,8 +467,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, style, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -478,8 +486,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, provider, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default; @@ -498,8 +505,7 @@ yield return Gold; #endif out CustomerType result) { if(System.Int32.TryParse(s, out var r)) { - result = FromValue(r); - return true; + return TryFromValue(r, out result); } result = default;