public static bool IsNumericType <T>(T value, TypeIsOptions isOptions = TypeIsOptions.Default) { return(IsNumericType(value.GetUnboxedType(), isOptions)); }
/// <summary> /// Determine whether the given type is a tuple type.<br /> /// 判断给定的类型是否为元组类型 /// </summary> /// <param name="type"></param> /// <param name="ofOptions"></param> /// <param name="isOptions"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static bool IsTupleType(Type type, TypeOfOptions ofOptions = TypeOfOptions.Owner, TypeIsOptions isOptions = TypeIsOptions.Default) { if (type is null) { return(false); } if (isOptions == TypeIsOptions.IgnoreNullable) { type = TypeConv.GetNonNullableType(type); } if (type == typeof(Tuple) || type == typeof(ValueTuple)) { return(true); } while (type != null) { if (type.IsGenericType) { var genType = type.GetGenericTypeDefinition(); if (genType == typeof(Tuple <>) || genType == typeof(Tuple <,>) || genType == typeof(Tuple <, ,>) || genType == typeof(Tuple <, , ,>) || genType == typeof(Tuple <, , , ,>) || genType == typeof(Tuple <, , , , ,>) || genType == typeof(Tuple <, , , , , ,>) || genType == typeof(Tuple <, , , , , , ,>) || genType == typeof(Tuple <, , , , , , ,>)) { return(true); } if (genType == typeof(ValueTuple <>) || genType == typeof(ValueTuple <,>) || genType == typeof(ValueTuple <, ,>) || genType == typeof(ValueTuple <, , ,>) || genType == typeof(ValueTuple <, , , ,>) || genType == typeof(ValueTuple <, , , , ,>) || genType == typeof(ValueTuple <, , , , , ,>) || genType == typeof(ValueTuple <, , , , , , ,>) || genType == typeof(ValueTuple <, , , , , , ,>)) { return(true); } } if (ofOptions == TypeOfOptions.Owner) { break; } type = type.BaseType; } return(false); }
public static bool IsValueTupleType <T>(T value, TypeOfOptions ofOptions = TypeOfOptions.Owner, TypeIsOptions isOptions = TypeIsOptions.Default) { var type = value?.GetUnboxedType(); return(type is not null && IsValueTupleType(type, ofOptions, isOptions)); }
public static bool IsNumericType <T>(TypeIsOptions isOptions = TypeIsOptions.Default) { return(IsNumericType(typeof(T), isOptions)); }
/// <summary> /// Required Numeric <br /> /// 数字需要满足 /// </summary> /// <param name="registrar"></param> /// <param name="isOptions"></param> /// <typeparam name="T"></typeparam> /// <typeparam name="TVal"></typeparam> /// <returns></returns> public static IPredicateValidationRegistrar <T, TVal> RequiredNumeric <T, TVal>(this IValueFluentValidationRegistrar <T, TVal> registrar, TypeIsOptions isOptions = TypeIsOptions.Default) { registrar._impl().ExposeValueRuleBuilder2().RequiredNumeric(isOptions); return((IPredicateValidationRegistrar <T, TVal>)registrar); }
public static bool IsValueTupleType <T>(TypeOfOptions ofOptions = TypeOfOptions.Owner, TypeIsOptions isOptions = TypeIsOptions.Default) { return(IsValueTupleType(typeof(T), ofOptions, isOptions)); }
/// <summary> /// The constraint type must be of numeric type. /// </summary> /// <returns></returns> public static IPredicateValueRuleBuilder <T, TVal> RequiredNumeric <T, TVal>(this IValueRuleBuilder <T, TVal> builder, TypeIsOptions isOptions = TypeIsOptions.Default) { var current = builder._impl(); current.State.CurrentToken = new ValueRequiredNumericToken(current._contract, isOptions); return(current); }
public static bool IsObjectDerivedFrom <TSource>(TSource value, Type parentType, TypeIsOptions isOptions = TypeIsOptions.Default, TypeDerivedOptions derivedOptions = TypeDerivedOptions.Default) => TypeReflections.IsObjectDerivedFrom(value, parentType, isOptions, derivedOptions);
public static bool IsNumericType <T>(T value, TypeIsOptions isOptions = TypeIsOptions.Default) => Types.IsNumericType(value, isOptions);
/// <inheritdoc /> public ValueRequiredNumericToken(VerifiableMemberContract contract, TypeIsOptions isOptions = TypeIsOptions.Default) : base(contract, TypeClass.DecimalClazz, false, Name, null, true) { _isOptions = isOptions; }
public static bool IsNumericType(Type type, TypeIsOptions isOptions = TypeIsOptions.Default) => Types.IsNumericType(type, isOptions);
public static bool IsEnumType <T>(TypeIsOptions isOptions = TypeIsOptions.Default) => Types.IsEnumType <T>(isOptions);
public static bool IsObjectDerivedFrom <TSource, TParent>(TSource value, TypeIsOptions isOptions = TypeIsOptions.Default) => TypeReflections.IsObjectDerivedFrom <TSource, TParent>(value, isOptions);
/// <summary> /// Determine whether the given parameter is a struct type.<br /> /// 判断给定的参数是否为数结构类型 /// </summary> /// <param name="parameter"></param> /// <param name="isOptions"></param> /// <returns></returns> public static bool IsStructType(this ParameterInfo parameter, TypeIsOptions isOptions = TypeIsOptions.Default) { return(Types.IsStructType(MemberVisitHelper.GetActualType(parameter), isOptions)); }
public static bool IsObjectDerivedFrom <TSource>(TSource value, Type parentType, TypeIsOptions isOptions = TypeIsOptions.Default, TypeDerivedOptions derivedOptions = TypeDerivedOptions.Default) { if (parentType is null) { throw new ArgumentNullException(nameof(parentType)); } return(isOptions switch { TypeIsOptions.Default => value is not null && IsTypeDerivedFrom(typeof(TSource), parentType, derivedOptions), TypeIsOptions.IgnoreNullable => IsTypeDerivedFrom(typeof(TSource), parentType, derivedOptions), _ => value is not null && IsTypeDerivedFrom(typeof(TSource), parentType, derivedOptions) });
/// <summary> /// Determine whether the given member is a numeric type.<br /> /// 判断给定的成员是否为数字类型。 /// </summary> /// <param name="member">要检查的类型</param> /// <param name="options"></param> /// <returns>是否是数值类型</returns> public static bool IsNumeric(this MemberInfo member, TypeIsOptions options = TypeIsOptions.Default) { return(Types.IsNumericType(MemberVisitHelper.GetActualType(member), options)); }
public static bool IsCollectionType <T>(T value, TypeIsOptions isOptions = TypeIsOptions.Default) => Types.IsCollectionType(value, isOptions);