Skip to content

Commit

Permalink
chore: remove redundant type conversions
Browse files Browse the repository at this point in the history
It's redundant code because custom data comparison logics(`CustomEqualityEquivalencyStep`) are added at recent commit
  • Loading branch information
filzrev committed Oct 6, 2024
1 parent 657b118 commit 289a4b7
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/Docfx.DataContracts.Common/JTokenConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ public static T Convert<T>(object obj)
return jToken.ToObject<T>();
}

// Custom code path for `System.Text.Json` deserialization.
// `ObjectToInferredTypesConverter` deserialize items as `List<object>`.
// So it need to convert `List<object>` to `List<TItem>`.
if (obj is List<object> list && IsListType<T>())
{
var json = JsonUtility.Serialize(list);
var result = JsonUtility.Deserialize<T>(new StringReader(json));
return result;
}

throw new InvalidCastException();
}

private static bool IsListType<T>()
{
var type = typeof(T);
return type.GetTypeInfo().IsGenericType
&& type.GetGenericTypeDefinition() == typeof(List<>);
}
}

0 comments on commit 289a4b7

Please sign in to comment.