internal static List <Field> GetFields(Type type) { #if !STANDALONE if (type.Is <Entity>()) { return(EntityType.FromNativeType(type).Fields.Select(x => new Field() { Name = x.Name, Get = new Func <object, object>(y => { var ent = (Entity)y; return x.IsStoredIn(ent) ? x.GetStoredValueDirect(ent) : null; }), Type = x.FieldType.NativeType }).ToList()); } ; #endif var emptyArray = new object[] { }; var fields = type.GetTypeInfo().IsPrimitive || type.GetTypeInfo().IsEnum || type == typeof(string) ? new[] { new Field { Name = "Value", Get = new Func <object, object>(y => y), Type = type } }.ToList() : type.GetFields(BindingFlags.Instance | BindingFlags.Public) #if !STANDALONE .Where(x => x.GetCustomAttribute <RestrictedAccessAttribute>() == null) #endif .Select(x => new Field { Name = x.Name, Member = x, Get = ReflectionHelper.GetGetter <object, object>(x), Type = x.FieldType }) .Union(type.GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(x => x.GetIndexParameters().Length == 0 #if !STANDALONE && x.DeclaringType != typeof(Entity) && x.GetMethod.GetCustomAttribute <RestrictedAccessAttribute>() == null #endif ) .Select(x => new Field { Name = x.Name, Member = x, Get = ReflectionHelper.GetGetter <object, object>(x), Type = x.PropertyType })) .ToList(); foreach (var field in fields) { var t = field.Type; if (t.GetTypeInfo().IsGenericType&& t.GetGenericTypeDefinition() == typeof(Nullable <>)) { t = Nullable.GetUnderlyingType(t); } field.IsNumeric = NumericTypes.Contains(t); } return(fields); }
public static string BuildElasticMapping <T>(string elasticType, IEnumerable <ElasticMappingConfigObject> analyzerConfiguration = null) { return(new MapBuilder <T>() .RootObject(elasticType, ro => ro .Properties(pr => { typeof(T).GetProperties().ToList().ForEach(ord => { if (ord.PropertyType == typeof(Guid)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f .String(ord.Name, sp => sp.Analyzer("caseinsensitive")))); } else if (ord.PropertyType == typeof(String)) { var indexAnalyzer = "autocomplete"; var searchAnalyzer = DefaultAnalyzers.standard; if (analyzerConfiguration != null && analyzerConfiguration.Any()) { var fieldCfg = analyzerConfiguration.SingleOrDefault(t => t.fieldName == ord.Name); if (fieldCfg != null) { indexAnalyzer = fieldCfg.analyzerName; if (!String.IsNullOrEmpty(fieldCfg.searchAnalyzer)) { searchAnalyzer = (DefaultAnalyzers)Enum.Parse(typeof(DefaultAnalyzers), fieldCfg.searchAnalyzer); } } } pr.MultiField(ord.Name, mfp => mfp.Fields(f => f .String(ord.Name, sp => sp.IndexAnalyzer(indexAnalyzer).SearchAnalyzer(searchAnalyzer)) .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")))); } else if (ord.PropertyType == typeof(DateTime)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Date(ord.Name))); } else if (ord.PropertyType == typeof(Boolean)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Boolean(ord.Name))); } else if (NumericTypes.Contains(ord.PropertyType)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Number(ord.Name))); } }); return pr; })).BuildBeautified()); }
private string GetInputTypeFromModel(Type modelType) { if (NumericTypes.Contains(modelType)) { return("number"); } if (DateTypes.Contains(modelType)) { return("date"); } if (modelType == typeof(string)) { return("text"); } return(string.Empty); }
private static string DeriveJsonTypeFromType(Type dataType) { if (NumericTypes.Contains(dataType)) { return("number"); } switch (dataType.Name) { case "Boolean": return("boolean"); case "DateTime": return("date"); case "String": return("string"); default: return("object"); } ; }
public unsafe Vector <T> AsVector() { int count = Vector <T> .Count; if (!NumericTypes.Contains(CLRType)) { throw new InvalidOperationException($"{CLRType.Name} is not a numeric type."); } else if (length != count) { throw new InvalidOperationException($"The length of the memory buffer must be {Vector<T>.Count} elements to create a vector of type {CLRType.Name}."); } else { Retain(); object[] args = new object[2] { ptr, 0 }; Vector <T> v = (Vector <T>)VectorInternalConstructorUsingPointer.Invoke(args); return(v); } }
/// <summary> /// Initializes a new instance of the <see cref="ExtendedTypeInfo" /> class. /// </summary> /// <param name="t">The t.</param> public ExtendedTypeInfo(Type t) { Type = t ?? throw new ArgumentNullException(nameof(t)); IsNullableValueType = Type.GetTypeInfo().IsGenericType&& Type.GetGenericTypeDefinition() == typeof(Nullable <>); IsValueType = t.GetTypeInfo().IsValueType; UnderlyingType = IsNullableValueType ? new NullableConverter(Type).UnderlyingType : Type; IsNumeric = NumericTypes.Contains(UnderlyingType); // Extract the TryParse method info try { TryParseMethodInfo = UnderlyingType.GetMethod(TryParseMethodName, new[] { typeof(string), typeof(NumberStyles), typeof(IFormatProvider), UnderlyingType.MakeByRefType() }) ?? UnderlyingType.GetMethod(TryParseMethodName, new[] { typeof(string), UnderlyingType.MakeByRefType() }); _tryParseParameters = TryParseMethodInfo?.GetParameters(); } catch { // ignored } // Extract the ToString method Info try { ToStringMethodInfo = UnderlyingType.GetMethod(ToStringMethodName, new[] { typeof(IFormatProvider) }) ?? UnderlyingType.GetMethod(ToStringMethodName, new Type[] { }); _toStringArgumentLength = ToStringMethodInfo?.GetParameters().Length ?? 0; } catch { // ignored } }
/// <summary> /// Determines whether the provided type is a known numeric type /// (ie int / short / byte / double / float / decimal ) /// </summary> /// <param name="type">Type to operate on</param> /// <returns></returns> public static bool IsNumericType(this Type type) { return(NumericTypes.Contains(type)); }
public static bool IsNumeric(this Type t) => NumericTypes.Contains(t);
public static bool IsNumericType <T>() { return(NumericTypes.Contains(typeof(T))); }
/// <summary> /// Indicates whether or not a particular <see cref="Type"/> is numeric or not /// </summary> public static bool IsNumeric(this Type type) { return(NumericTypes.Contains(type) || NumericTypes.Contains(Nullable.GetUnderlyingType(type))); }