Added non-generic CanGet/Set methods.

pull/83/head
David Hall 2019-10-08 20:13:17 -06:00
parent 5c47d6de8f
commit 4f087df55c
1 changed files with 20 additions and 10 deletions

View File

@ -79,14 +79,19 @@ namespace Vanara.InteropServices
/// <typeparam name="T">The corresponding type to look for.</typeparam> /// <typeparam name="T">The corresponding type to look for.</typeparam>
/// <typeparam name="TEnum">The type of the enum.</typeparam> /// <typeparam name="TEnum">The type of the enum.</typeparam>
/// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param> /// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param>
/// <returns> /// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
/// <see langword="true" /> if this instance can get the specified value; otherwise, <see langword="false" />. public static bool CanGet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum => CanGet(typeof(T), out value);
/// </returns>
public static bool CanGet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum /// <summary>Determines whether an enum value exists that supports a corresponding type of <typeparamref name="T"/>.</summary>
/// <typeparam name="TEnum">The type of the enum.</typeparam>
/// <param name="typeRef">The corresponding type to look for.</param>
/// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param>
/// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
public static bool CanGet<TEnum>(Type typeRef, out TEnum value) where TEnum : struct, System.Enum
{ {
foreach (TEnum v in Enum.GetValues(typeof(TEnum))) foreach (TEnum v in Enum.GetValues(typeof(TEnum)))
{ {
if (CanGet(v, typeof(T))) if (CanGet(v, typeRef))
{ {
value = v; value = v;
return true; return true;
@ -118,14 +123,19 @@ namespace Vanara.InteropServices
/// <typeparam name="T">The corresponding type to look for.</typeparam> /// <typeparam name="T">The corresponding type to look for.</typeparam>
/// <typeparam name="TEnum">The type of the enum.</typeparam> /// <typeparam name="TEnum">The type of the enum.</typeparam>
/// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param> /// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param>
/// <returns> /// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
/// <see langword="true" /> if this instance can get the specified value; otherwise, <see langword="false" />. public static bool CanSet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum => CanSet(typeof(T), out value);
/// </returns>
public static bool CanSet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum /// <summary>Determines whether an enum value exists that supports a corresponding type of <typeparamref name="T"/>.</summary>
/// <typeparam name="TEnum">The type of the enum.</typeparam>
/// <param name="typeRef">The type supplied by the user to validate.</param>
/// <param name="value">The value of type <typeparamref name="TEnum"/> that has the corresponding type <typeparamref name="T"/>.</param>
/// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
public static bool CanSet<TEnum>(Type typeRef, out TEnum value) where TEnum : struct, System.Enum
{ {
foreach (TEnum v in Enum.GetValues(typeof(TEnum))) foreach (TEnum v in Enum.GetValues(typeof(TEnum)))
{ {
if (CanSet(v, typeof(T))) if (CanSet(v, typeRef))
{ {
value = v; value = v;
return true; return true;