diff --git a/MLEM.Data/Json/StaticJsonConverter.cs b/MLEM.Data/Json/StaticJsonConverter.cs index be0a70a..2829d3e 100644 --- a/MLEM.Data/Json/StaticJsonConverter.cs +++ b/MLEM.Data/Json/StaticJsonConverter.cs @@ -7,7 +7,7 @@ using Newtonsoft.Json; namespace MLEM.Data.Json { /// /// A that doesn't actually serialize the object, but instead serializes the name given to it by the underlying . - /// Optionally, the name of a can be passed to this converter when used in the by passing the arguments for the constructor as . + /// Optionally, the name of a can be passed to this converter when used in the by passing the arguments for the constructor as . /// /// The type of the object to convert public class StaticJsonConverter : JsonConverter { @@ -27,10 +27,10 @@ namespace MLEM.Data.Json { /// /// Creates a new static json converter by finding the underlying from the given type and member name /// - /// The name of the type that the dictionary is in + /// The type that the dictionary is declared in /// The name of the dictionary itself - public StaticJsonConverter(string typeName, string memberName) : - this(GetEntries(typeName, memberName)) { + public StaticJsonConverter(Type type, string memberName) : + this(GetEntries(type, memberName)) { } /// @@ -49,9 +49,8 @@ namespace MLEM.Data.Json { return ret; } - private static Dictionary GetEntries(string typeName, string memberName) { + private static Dictionary GetEntries(Type type, string memberName) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; - var type = Type.GetType(typeName) ?? throw new ArgumentException($"Type {typeName} does not exist", nameof(typeName)); var value = type.GetProperty(memberName, flags)?.GetValue(null) ?? type.GetField(memberName, flags)?.GetValue(null); if (value == null) throw new ArgumentException($"There is no property or field value for name {memberName}", nameof(memberName));