Browse Source

Make JsonConverter's Write method simple.

pull/5952/head
maliming 6 years ago
parent
commit
fb4f46d4d4
  1. 10
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/SelectionStringValueItemSourceJsonConverter.cs
  2. 18
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/StringValueTypeJsonConverter.cs
  3. 22
      modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/ValueValidatorJsonConverter.cs

10
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/SelectionStringValueItemSourceJsonConverter.cs

@ -26,15 +26,7 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
public override void Write(Utf8JsonWriter writer, ISelectionStringValueItemSource value, JsonSerializerOptions options)
{
var newOptions = JsonSerializerOptionsHelper.Create(options, this);
if (value.GetType() == typeof(StaticSelectionStringValueItemSource))
{
JsonSerializer.Serialize(writer, (StaticSelectionStringValueItemSource)value, newOptions);
}
else
{
throw new JsonException("Unknown ISelectionStringValueItemSource type!");
}
JsonSerializer.Serialize(writer, value, value.GetType(), newOptions);
}
}
}

18
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/StringValueTypeJsonConverter.cs

@ -25,23 +25,7 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
public override void Write(Utf8JsonWriter writer, IStringValueType value, JsonSerializerOptions options)
{
var newOptions = JsonSerializerOptionsHelper.Create(options, this);
if (value.GetType() == typeof(FreeTextStringValueType))
{
JsonSerializer.Serialize(writer, (FreeTextStringValueType)value, newOptions);
}
else if (value.GetType() == typeof(SelectionStringValueType))
{
JsonSerializer.Serialize(writer, (SelectionStringValueType)value, newOptions);
}
else if (value.GetType() == typeof(ToggleStringValueType))
{
JsonSerializer.Serialize(writer, (ToggleStringValueType)value, newOptions);
}
else
{
throw new JsonException("Unknown IStringValueType type!");
}
JsonSerializer.Serialize(writer, value, value.GetType(), newOptions);
}
}
}

22
modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/ValueValidatorJsonConverter.cs

@ -33,27 +33,7 @@ namespace Volo.Abp.FeatureManagement.JsonConverters
public override void Write(Utf8JsonWriter writer, IValueValidator value, JsonSerializerOptions options)
{
var newOptions = JsonSerializerOptionsHelper.Create(options, this);
if (value.GetType() == typeof(AlwaysValidValueValidator))
{
JsonSerializer.Serialize(writer, (AlwaysValidValueValidator)value, newOptions);
}
else if (value.GetType() == typeof(BooleanValueValidator))
{
JsonSerializer.Serialize(writer, (BooleanValueValidator)value, newOptions);
}
else if (value.GetType() == typeof(NumericValueValidator))
{
JsonSerializer.Serialize(writer, (NumericValueValidator)value, newOptions);
}
else if (value.GetType() == typeof(StringValueValidator))
{
JsonSerializer.Serialize(writer, (StringValueValidator)value, newOptions);
}
else
{
throw new JsonException("Unknown IValueValidator type!");
}
JsonSerializer.Serialize(writer, value, value.GetType(), newOptions);
}
protected virtual IValueValidator CreateValueValidatorByName(string name)

Loading…
Cancel
Save