From a7b5f7bea0a7491797e82d2eaabffd6d61161d37 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 15 Dec 2019 15:53:31 -0600 Subject: [PATCH] Redid UseConverterAttribute type checking --- IPA.Loader/Config/Stores/Attributes.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/IPA.Loader/Config/Stores/Attributes.cs b/IPA.Loader/Config/Stores/Attributes.cs index d2708b30..d9361054 100644 --- a/IPA.Loader/Config/Stores/Attributes.cs +++ b/IPA.Loader/Config/Stores/Attributes.cs @@ -31,14 +31,12 @@ namespace IPA.Config.Stores.Attributes /// /// Gets the type of the converter to use. /// - public Type ConverterType { get; private set; } + public Type ConverterType { get; } /// /// Gets the target type of the converter if it is avaliable at instantiation time, otherwise /// . /// - public Type ConverterTargetType => ConverterType.BaseType.IsGenericType ? - ConverterType.BaseType.GetGenericArguments()[0] : - null; + public Type ConverterTargetType { get; } /// /// Gets whether or not this converter is a generic . @@ -53,10 +51,16 @@ namespace IPA.Config.Stores.Attributes { ConverterType = converterType; + var baseT = ConverterType.BaseType; + while (baseT != null && baseT != typeof(object) && + (!baseT.IsGenericType || baseT.GetGenericTypeDefinition() != typeof(ValueConverter<>))) + baseT = baseT.BaseType; + if (baseT == typeof(object)) ConverterTargetType = null; + else ConverterTargetType = baseT.GetGenericArguments()[0]; + var implInterface = ConverterType.GetInterfaces().Contains(typeof(IValueConverter)); - var inheritGeneric = ConverterType.BaseType.IsGenericType && - ConverterType.BaseType.GetGenericTypeDefinition() == typeof(ValueConverter<>); - if (!implInterface && !inheritGeneric) throw new ArgumentException("Type is not a value converter!"); + + if (ConverterTargetType == null && !implInterface) throw new ArgumentException("Type is not a value converter!"); } }