diff --git a/Core/InteropServices/CorrespondingTypeAttribute.cs b/Core/InteropServices/CorrespondingTypeAttribute.cs index 32f2f13d..efc7a58e 100644 --- a/Core/InteropServices/CorrespondingTypeAttribute.cs +++ b/Core/InteropServices/CorrespondingTypeAttribute.cs @@ -79,14 +79,19 @@ namespace Vanara.InteropServices /// The corresponding type to look for. /// The type of the enum. /// The value of type that has the corresponding type . - /// - /// if this instance can get the specified value; otherwise, . - /// - public static bool CanGet(out TEnum value) where TEnum : struct, System.Enum + /// if this instance can get the specified value; otherwise, . + public static bool CanGet(out TEnum value) where TEnum : struct, System.Enum => CanGet(typeof(T), out value); + + /// Determines whether an enum value exists that supports a corresponding type of . + /// The type of the enum. + /// The corresponding type to look for. + /// The value of type that has the corresponding type . + /// if this instance can get the specified value; otherwise, . + public static bool CanGet(Type typeRef, out TEnum value) where TEnum : struct, System.Enum { foreach (TEnum v in Enum.GetValues(typeof(TEnum))) { - if (CanGet(v, typeof(T))) + if (CanGet(v, typeRef)) { value = v; return true; @@ -118,14 +123,19 @@ namespace Vanara.InteropServices /// The corresponding type to look for. /// The type of the enum. /// The value of type that has the corresponding type . - /// - /// if this instance can get the specified value; otherwise, . - /// - public static bool CanSet(out TEnum value) where TEnum : struct, System.Enum + /// if this instance can get the specified value; otherwise, . + public static bool CanSet(out TEnum value) where TEnum : struct, System.Enum => CanSet(typeof(T), out value); + + /// Determines whether an enum value exists that supports a corresponding type of . + /// The type of the enum. + /// The type supplied by the user to validate. + /// The value of type that has the corresponding type . + /// if this instance can get the specified value; otherwise, . + public static bool CanSet(Type typeRef, out TEnum value) where TEnum : struct, System.Enum { foreach (TEnum v in Enum.GetValues(typeof(TEnum))) { - if (CanSet(v, typeof(T))) + if (CanSet(v, typeRef)) { value = v; return true;