mirror of https://github.com/abpframework/abp.git
10 changed files with 60 additions and 89 deletions
@ -0,0 +1,17 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Text.Json; |
||||
|
using System.Text.Json.Serialization; |
||||
|
|
||||
|
namespace Volo.Abp.FeatureManagement.JsonConverters |
||||
|
{ |
||||
|
internal static class JsonSerializerOptionsHelper |
||||
|
{ |
||||
|
public static JsonSerializerOptions Create(JsonSerializerOptions baseOptions, JsonConverter removeConverter, params JsonConverter[] addConverters) |
||||
|
{ |
||||
|
var options = new JsonSerializerOptions(baseOptions); |
||||
|
options.Converters.RemoveAll(x => x == removeConverter); |
||||
|
options.Converters.AddIfNotContains(addConverters); |
||||
|
return options; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,24 +0,0 @@ |
|||||
using System; |
|
||||
using System.Text.Json; |
|
||||
using System.Text.Json.Serialization; |
|
||||
using Volo.Abp.Validation.StringValues; |
|
||||
|
|
||||
namespace Volo.Abp.FeatureManagement.JsonConverters |
|
||||
{ |
|
||||
public class LocalizableStringInfoJsonConverter : JsonConverter<LocalizableStringInfo> |
|
||||
{ |
|
||||
public override LocalizableStringInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
||||
{ |
|
||||
var rootElement = JsonDocument.ParseValue(ref reader).RootElement; |
|
||||
return new LocalizableStringInfo( |
|
||||
rootElement.GetProperty("ResourceName").GetString(), |
|
||||
rootElement.GetProperty("Name").GetString() |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public override void Write(Utf8JsonWriter writer, LocalizableStringInfo value, JsonSerializerOptions options) |
|
||||
{ |
|
||||
JsonSerializer.Serialize(writer, value); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,36 +0,0 @@ |
|||||
using System; |
|
||||
using System.Text.Json; |
|
||||
using System.Text.Json.Serialization; |
|
||||
using Volo.Abp.Validation.StringValues; |
|
||||
|
|
||||
namespace Volo.Abp.FeatureManagement.JsonConverters |
|
||||
{ |
|
||||
public class SelectionStringValueItemJsonConverter : JsonConverter<ISelectionStringValueItem> |
|
||||
{ |
|
||||
public override ISelectionStringValueItem Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
||||
{ |
|
||||
var rootElement = JsonDocument.ParseValue(ref reader).RootElement; |
|
||||
|
|
||||
var jsonSerializerOptions = new JsonSerializerOptions(); |
|
||||
jsonSerializerOptions.Converters.Add(new LocalizableStringInfoJsonConverter()); |
|
||||
|
|
||||
return new LocalizableSelectionStringValueItem |
|
||||
{ |
|
||||
Value = rootElement.GetProperty("Value").GetString(), |
|
||||
DisplayText = JsonSerializer.Deserialize<LocalizableStringInfo>(rootElement.GetProperty("DisplayText").GetRawText(), jsonSerializerOptions) |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
public override void Write(Utf8JsonWriter writer, ISelectionStringValueItem value, JsonSerializerOptions options) |
|
||||
{ |
|
||||
if (value.GetType() == typeof(LocalizableStringInfo)) |
|
||||
{ |
|
||||
JsonSerializer.Serialize(writer, (LocalizableSelectionStringValueItem)value); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
throw new JsonException("Unknown ISelectionStringValueItem type!"); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue