コード例 #1
0
        public static TypeInspector Inspector(this Type type)
        {
            if (!_typeInspectorCache.Value.TryGetValue(type, out var inspector))
            {
                inspector = new TypeInspector(type);

                _typeInspectorCache.Value[type] = inspector;
            }

            return(inspector);
        }
コード例 #2
0
        private static TimeSpan?ToTimeSpan(object value, TypeInspector type)
        {
            if (type.Is(TypeFlags.Integer64))
            {
                return(new TimeSpan(System.Convert.ToInt64(value)));
            }

            if (type.Is(TypeFlags.Numeric))
            {
                return(TimeSpan.FromSeconds(System.Convert.ToDouble(value)));
            }

            return(null);
        }
コード例 #3
0
        public TypeInspector(Type type)
        {
            Type     = type;
            RealType = Nullable.GetUnderlyingType(Type) ?? Type;

            _typeInfo     = type.GetTypeInfo();
            _realTypeInfo = RealType.GetTypeInfo();

            if (type.IsArray)
            {
                _elementTypeInspector = type.GetElementType().Inspector();
            }

            TypeFlags = BuildTypeFlags();
        }
コード例 #4
0
        private static DateTime?ToDateTime(object value, TypeInspector type)
        {
            if (type.Is(TypeFlags.Integer64)) // Assume .NET ticks
            {
                return(new DateTime(System.Convert.ToInt64(value)));
            }

            if (type.Is(TypeFlags.Integer32)) // Assume Unix seconds since 1970-01-01
            {
                return(new DateTime(1970, 1, 1).AddSeconds(System.Convert.ToInt32(value)));
            }

            if (type.Is(TypeFlags.FloatingPoint))
            {
                return(JulianToDateTime(System.Convert.ToDouble(value)));
            }

            return(null);
        }