Example #1
0
        public static string GetNiceTypeName(System.Type type, NamingOptions options)
        {
            if (options != null && options.NameOverrideFunc != null)
            {
                string s = options.NameOverrideFunc(type);
                if (s != null)
                {
                    return(s);
                }
            }

            if (ReflectionUtil.IsNullableType(type))
            {
                var actualtype = type.GetGenericArguments()[0];
                return(ReflectionUtil.GetNiceTypeName(actualtype, options) + "?");
            }

            if (type.IsArray)
            {
                var at = type.GetElementType();
                return(String.Format("{0}[]", ReflectionUtil.GetNiceTypeName(at, options)));
            }

            if (type.IsGenericType)
            {
                var sb     = new System.Text.StringBuilder();
                var tokens = type.Name.Split('`');

                sb.Append(tokens[0]);
                var gas      = type.GetGenericArguments();
                var ga_names = gas.Select(i => ReflectionUtil.GetNiceTypeName(i, options));

                sb.Append("<");
                sb.AppendJoin(", ", ga_names);
                sb.Append(">");
                return(sb.ToString());
            }

            return(type.Name);
        }