public static object InternalToObject(JsTypeFunction enumType, object value) { var enumsByValue = enumsByTypeAndValue[enumType.TypeName]; Enum result = enumsByValue.GetOrDefault(value); if (result != null) { return(result); } else { // Otherwise it's an enum value that isn't represented by a declared member. In // this case, we need to box the value and then force it to be recognized as the // enum type. result = Jsni.@new(Jsni.reference("Number"), value.As <JsObject>()).As <Enum>(); foreach (var property in enumType.member("prototype")) { result.As <JsObject>()[property] = enumType.member("prototype")[property]; } foreach (var property in Jsni.type <Enum>().member("prototype")) { result.As <JsObject>()[property] = Jsni.type <Enum>().member("prototype")[property]; } result.___type = enumType; result.As <JsObject>().memberset("value", value.As <JsObject>()); enumsByValue[value] = result; return(result); } }
/// <summary> /// 判断值是否存在于集合中,主要用于位枚举的判断 /// </summary> /// <param name="col"></param> /// <param name="value"></param> /// <returns></returns> public static bool Contains(this Enum col, Enum value) { if (col.GetType() != value.GetType()) { return false; } if (!col.Equals(value)) { return (col.As<int>() & value.As<int>()) != 0; } return true; }