コード例 #1
0
        /// <summary>
        /// Gets the javascript type name for the given type.
        /// </summary>
        /// <param name="propType">The property Type</param>
        /// <returns>The type name for that property type</returns>
        private string GetJavascriptTypeName(Type propType)
        {
            TypeCode code = Type.GetTypeCode(propType);

            string typeName;

            if (TypeUtils.IsNumericType(propType))
            {
                typeName = "Number";
            }
            else if (code == TypeCode.String)
            {
                typeName = "String";
            }
            else if (code == TypeCode.Boolean)
            {
                typeName = "Boolean";
            }
            else if (TypeUtils.IsList(propType))
            {
                typeName = "Array";
            }
            else
            {
                typeName = ClientScriptGenHelper.TryFindExtractedType(this, propType);
                if (string.IsNullOrEmpty(typeName))
                {
                    typeName = TypeUtils.GetTypeName(propType);
                }
            }

            return(typeName);
        }
コード例 #2
0
        /// <summary>
        /// Gets the Typescript object type name for the given type.
        ///
        /// TODO: this could be better written and needs to support dictionaries
        /// </summary>
        /// <param name="propType">The property Type</param>
        /// <returns>The type name for that property type</returns>
        private string GetTypescriptTypeName(Type propType)
        {
            Type underlyingType = propType;

            if (propType.IsGenericType)
            {
                if (propType.GetGenericTypeDefinition() == typeof(Nullable <>) ||
                    propType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    underlyingType = propType.GetGenericArguments()[0];
                }
            }
            TypeCode code = Type.GetTypeCode(underlyingType);
            string   typeName;

            if (TypeUtils.IsNumericType(underlyingType))
            {
                typeName = "number";
            }
            else if (code == TypeCode.String || code == TypeCode.DateTime)
            {
                typeName = "string";
            }
            else if (code == TypeCode.Boolean)
            {
                typeName = "boolean";
            }
            else
            {
                typeName = ClientScriptGenHelper.TryFindExtractedType(this, underlyingType);
                if (string.IsNullOrEmpty(typeName))
                {
                    typeName = "any";
                }
            }

            if (TypeUtils.IsList(propType))
            {
                typeName += "[]";
            }

            return(typeName);
        }