你好,我不知道如何调用下一个函数,你可以帮我在这里。调用函数<T>
函数检查值是否定义了枚举值。如果不是,则抛出异常。 警告:失败为[国旗]型我已经试过这样的事情枚举
public static T FailIfEnumIsNotDefined<T>(this T enumValue, string message = null)
where T:struct
{
var enumType = typeof (T);
if (!enumType.IsEnum)
{
throw new ArgumentOutOfRangeException(string.Format("Type {0} is not an Enum, therefore it cannot be checked if it is Defined not have defined.", enumType.FullName));
}
else if (!Enum.IsDefined(enumType, enumValue))
{
throw new ArgumentOutOfRangeException(string.Format("{1} Value {0} is not does not have defined value in Enum of type {0}. It should not be...", enumType.FullName, message ?? ""));
}
return enumValue;
}
,但我得到的错误。
var valueFormatted = tobeTested.FailIfNullOrEmptyEnumerable<string>();
你将不得不给我们更多关于该函数应该做什么的信息 – RononDex
'string'是'class'而不是'struct',你调用方法的方式不正确。 – Ric
对提供的枚举类型进行扩展似乎没有用处。您需要扩展字符串或对象。检查我的答案,如果这是你需要的 – Akanksha