Esempio n. 1
0
        public sealed override String ToString()
        {
            RuntimeType shadowNamedType = ShadowNamedTypeIfAvailable;

            if (shadowNamedType != null)
            {
                return(shadowNamedType.ToString());
            }

            return(_runtimeTypeHandle.LastResortToString);
        }
        public sealed override String ToString()
        {
            ConstructedGenericTypeKey key = this.ConstructedGenericTypeKeyIfAvailable;

            if (!key.IsAvailable)
            {
                return(this.LastResortToString);
            }

            // Get the FullName of the generic type definition in a pay-for-play safe way.
            RuntimeType genericTypeDefinition       = key.GenericTypeDefinition;
            String      genericTypeDefinitionString = null;

            if (genericTypeDefinition.InternalNameIfAvailable != null)   // Want to avoid "cry-wolf" exceptions: if we can't even get the simple name, don't bother getting the FullName.
            {
                // Given our current pay for play policy, it should now be safe to attempt getting the FullName. (But guard with a try-catch in case this assumption is wrong.)
                try
                {
                    genericTypeDefinitionString = genericTypeDefinition.FullName;
                }
                catch (Exception)
                {
                }
            }
            // If all else fails, use the ToString() - it won't match the legacy CLR but with no metadata, we can't match it anyway.
            if (genericTypeDefinitionString == null)
            {
                genericTypeDefinitionString = genericTypeDefinition.ToString();
            }

            // Now, append the generic type arguments.
            String s = genericTypeDefinitionString;

            s += "[";
            Type[] genericTypeArguments = key.GenericTypeArguments;
            for (int i = 0; i < genericTypeArguments.Length; i++)
            {
                if (i != 0)
                {
                    s += ",";
                }
                s += genericTypeArguments[i].ToString();
            }
            s += "]";
            return(s);
        }