mirror of https://github.com/dahall/Vanara.git
Added non-generic CanGet/Set methods.
parent
5c47d6de8f
commit
4f087df55c
|
@ -79,14 +79,19 @@ namespace Vanara.InteropServices
|
|||
/// <typeparam name="T">The corresponding type to look for.</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>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if this instance can get the specified value; otherwise, <see langword="false" />.
|
||||
/// </returns>
|
||||
public static bool CanGet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum
|
||||
/// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
|
||||
public static bool CanGet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum => CanGet(typeof(T), out value);
|
||||
|
||||
/// <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)))
|
||||
{
|
||||
if (CanGet(v, typeof(T)))
|
||||
if (CanGet(v, typeRef))
|
||||
{
|
||||
value = v;
|
||||
return true;
|
||||
|
@ -118,14 +123,19 @@ namespace Vanara.InteropServices
|
|||
/// <typeparam name="T">The corresponding type to look for.</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>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if this instance can get the specified value; otherwise, <see langword="false" />.
|
||||
/// </returns>
|
||||
public static bool CanSet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum
|
||||
/// <returns><see langword="true"/> if this instance can get the specified value; otherwise, <see langword="false"/>.</returns>
|
||||
public static bool CanSet<T, TEnum>(out TEnum value) where TEnum : struct, System.Enum => CanSet(typeof(T), out value);
|
||||
|
||||
/// <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)))
|
||||
{
|
||||
if (CanSet(v, typeof(T)))
|
||||
if (CanSet(v, typeRef))
|
||||
{
|
||||
value = v;
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue