Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the TsCollection class with the specific CLR type.
        /// </summary>
        /// <param name="type">The CLR collection represented by this instance of the TsCollection.</param>
        public TsCollection(Type type)
            : base(type)
        {
            var enumerableType = TsType.GetEnumerableType(this.Type);

            if (enumerableType == this.Type)
            {
                this.ItemsType = TsType.Any;
            }
            else if (enumerableType != null)
            {
                this.ItemsType = TsType.Create(enumerableType);
            }
            else if (typeof(IEnumerable).IsAssignableFrom(this.Type))
            {
                this.ItemsType = TsType.Any;
            }
            else
            {
                throw new ArgumentException(string.Format("The type '{0}' is not collection.", this.Type.FullName));
            }

            this.Dimension = GetCollectionDimension(type);
        }