예제 #1
0
        public static string ToCompilableString(this Type type)
        {
            if (SerializationTools.TryGetBuiltInTypeToString(type, out var str))
            {
                return(str);
            }
            else if (type.IsGenericType)
            {
                return(type.FullName.Split('`')[0] +
                       "<" +
                       string.Join(", ", type.GetGenericArguments().Select(argType => argType.ToCompilableString()).ToArray()) +
                       ">");
            }
            else if (type.IsArray)
            {
                return(type.GetElementType().ToCompilableString() + "[" + new string(',', type.GetArrayRank() - 1) + "]");
            }

            return(type.IsNested ? type.FullName.Replace('+', '.') : type.FullName);
        }