Exemplo n.º 1
0
        internal static string Type(System.Type type)
        {
            if (type == null)
            {
                return(string.Empty);
            }
            string typeName;

            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                string        str           = ToStringCodeMethods.Type(type.GetGenericTypeDefinition());
                int           num           = str.LastIndexOf('`');
                int           length        = str.Length - (str.Length - num);
                StringBuilder stringBuilder = new StringBuilder(str, 0, length, 512);
                stringBuilder.Append('[');
                bool flag = true;
                foreach (System.Type genericArgument in type.GetGenericArguments())
                {
                    if (!flag)
                    {
                        stringBuilder.Append(',');
                    }
                    flag = false;
                    stringBuilder.Append(ToStringCodeMethods.Type(genericArgument));
                }
                stringBuilder.Append(']');
                typeName = stringBuilder.ToString();
            }
            else if (type.IsArray)
            {
                string        str           = ToStringCodeMethods.Type(type.GetElementType());
                StringBuilder stringBuilder = new StringBuilder(str, str.Length + 10);
                stringBuilder.Append("[");
                for (int index = 0; index < type.GetArrayRank() - 1; ++index)
                {
                    stringBuilder.Append(",");
                }
                stringBuilder.Append("]");
                typeName = stringBuilder.ToString();
            }
            else
            {
                typeName = TypeAccelerators.FindBuiltinAccelerator(type) ?? type.ToString();
            }
            if (!type.IsGenericParameter && !type.ContainsGenericParameters && LanguagePrimitives.ConvertStringToType(typeName, out Exception _) != type)
            {
                typeName = type.AssemblyQualifiedName;
            }
            return(typeName);
        }
Exemplo n.º 2
0
 public static string Type(PSObject instance) => instance == null ? string.Empty : ToStringCodeMethods.Type((System.Type)instance.BaseObject);