Esempio n. 1
0
        public static string GetTypeScriptTypeName(Type type)
        {
            if (type.IsGenericType)
            {
                var def = type.GetGenericTypeDefinition();
                if (def == typeof(List <>))
                {
                    return($"{TypeScript.GetTypeScriptTypeName(type.GetGenericArguments()[0])}[]");
                }
                if (def == typeof(Dictionary <,>))
                {
                    return($"Record<{string.Join(", ", type.GetGenericArguments().Select(at => TypeScript.GetTypeScriptTypeName(at)))}>");
                }
            }
            switch (type.Name)
            {
            case "String":
                return("string");

            case "Boolean":
                return("boolean");

            case "Int32":
            case "Double":
                return("number");
            }
            return(type.Name);
        }
Esempio n. 2
0
            public PropertyInfo(FieldInfo info)
            {
                var typeAlias = info.GetCustomAttribute <TypeAliasAttribute>()?.alias;

                this.name     = info.Name;
                this.optional = Nullable.GetUnderlyingType(info.FieldType) != null;
                this.type     = typeAlias ?? TypeScript.GetTypeScriptTypeName(this.optional
          ? info.FieldType.GetGenericArguments()[0]
          : info.FieldType);
                if (info.GetCustomAttributes().Any(a => (a as NullableAttribute) != null))
                {
                    this.optional = true;
                }
            }