Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Aug 21, 2024
1 parent 0403a39 commit a96e8c6
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/ConfigCatClient/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,38 @@ internal static SettingValue ToSettingValue(this JsonValue value, out SettingTyp
{
case Newtonsoft.Json.Linq.JTokenType.String:
settingType = SettingType.String;
return new SettingValue { StringValue = value.ConvertTo<string>() };
return new SettingValue { StringValue = Newtonsoft.Json.Linq.Extensions.Value<string>(value) };

case Newtonsoft.Json.Linq.JTokenType.Boolean:
settingType = SettingType.Boolean;
return new SettingValue { BoolValue = value.ConvertTo<bool>() };
return new SettingValue { BoolValue = Newtonsoft.Json.Linq.Extensions.Value<bool>(value) };

case Newtonsoft.Json.Linq.JTokenType.Integer when IsWithinAllowedIntRange(value):
settingType = SettingType.Int;
return new SettingValue { IntValue = value.ConvertTo<int>() };
return new SettingValue { IntValue = Newtonsoft.Json.Linq.Extensions.Value<int>(value) };

case Newtonsoft.Json.Linq.JTokenType.Float when IsWithinAllowedDoubleRange(value):
settingType = SettingType.Double;
return new SettingValue { DoubleValue = value.ConvertTo<double>() };
return new SettingValue { DoubleValue = Newtonsoft.Json.Linq.Extensions.Value<double>(value) };
}
#else
switch (value.ValueKind)
{
case Text.Json.JsonValueKind.String:
settingType = SettingType.String;
return new SettingValue { StringValue = value.ConvertTo(SourceGenSerializationContext.Default.String) };
return new SettingValue { StringValue = value.GetString() };

case Text.Json.JsonValueKind.False or Text.Json.JsonValueKind.True:
settingType = SettingType.Boolean;
return new SettingValue { BoolValue = value.ConvertTo(SourceGenSerializationContext.Default.Boolean) };
return new SettingValue { BoolValue = value.GetBoolean() };

case Text.Json.JsonValueKind.Number when value.TryGetInt32(out var _):
case Text.Json.JsonValueKind.Number when value.TryGetInt32(out var intValue):
settingType = SettingType.Int;
return new SettingValue { IntValue = value.ConvertTo(SourceGenSerializationContext.Default.Int32) };
return new SettingValue { IntValue = intValue };

case Text.Json.JsonValueKind.Number when value.TryGetDouble(out var _):
case Text.Json.JsonValueKind.Number when value.TryGetDouble(out var doubleValue):
settingType = SettingType.Double;
return new SettingValue { DoubleValue = value.ConvertTo(SourceGenSerializationContext.Default.Double) };
return new SettingValue { DoubleValue = doubleValue };
}
#endif

Expand Down Expand Up @@ -137,22 +137,6 @@ public static Setting ToSetting(this object? value)
return setting;
}

#if USE_NEWTONSOFT_JSON
private static TValue ConvertTo<TValue>(this JsonValue value)
{
Debug.Assert(typeof(TValue) != typeof(object), "Conversion to object is not supported.");
Debug.Assert(value.Type != Newtonsoft.Json.Linq.JTokenType.Null, "Tried to convert unexpected null value.");
return Newtonsoft.Json.Linq.Extensions.Value<TValue>(value)!;
}
#else
private static TValue ConvertTo<TValue>(this JsonValue value, Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo)
{
Debug.Assert(typeof(TValue) != typeof(object), "Conversion to object is not supported.");
Debug.Assert(value.ValueKind != Text.Json.JsonValueKind.Null, "Tried to convert unexpected null value.");
return Text.Json.JsonSerializer.Deserialize(value, jsonTypeInfo)!;
}
#endif

public static bool TryConvertNumericToDouble(this object value, out double number)
{
if (Type.GetTypeCode(value.GetType()) is
Expand Down

0 comments on commit a96e8c6

Please sign in to comment.