private static System.Type CalculateAverageType(System.Type inputType)
        {
            bool isNullable = false;

            if (inputType.IsNullable())
            {
                isNullable = true;
                inputType = inputType.NullableOf();
            }

            switch (System.Type.GetTypeCode(inputType))
            {
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.Single:
                case TypeCode.Double:
                    return isNullable ? typeof(double?) : typeof (double);
                case TypeCode.Decimal:
                    return isNullable ? typeof(decimal?) : typeof(decimal);
            }

            throw new NotSupportedException(inputType.FullName);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets TsTypeFamily of the CLR type.
        /// </summary>
        /// <param name="type">The CLR type to get TsTypeFamily of</param>
        /// <returns>TsTypeFamily of the CLR type</returns>
        internal static TsTypeFamily GetTypeFamily(System.Type type)
        {
            if (type.IsNullable()) {
                return TsType.GetTypeFamily(type.GetNullableValueType());
            }

            var isString = (type == typeof(string));
            var isEnumerable = typeof(IEnumerable).IsAssignableFrom(type);

            // surprisingly  Decimal isn't a primitive type
            if (isString || type.IsPrimitive || type.FullName == "System.Decimal" || type.FullName == "System.DateTime" || type.FullName == "System.DateTimeOffset" || type.FullName == "System.SByte") {
                return TsTypeFamily.System;
            } else if (isEnumerable) {
                return TsTypeFamily.Collection;
            }

            if (type.IsEnum) {
                return TsTypeFamily.Enum;
            }

            if ((type.IsClass && type.FullName != "System.Object") || type.IsValueType /* structures */ || type.IsInterface) {
                return TsTypeFamily.Class;
            }

            return TsTypeFamily.Type;
        }