public sealed override String ToString()
        {
            try
            {
                TypeContext            typeContext            = _contextTypeInfo.TypeContext;
                ReflectionTypeProvider reflectionTypeProvider = new ReflectionTypeProvider(throwOnError: false);
                RuntimeTypeInfo        fieldType = _field.DecodeSignature(reflectionTypeProvider, typeContext);

                string fieldTypeName;
                if (reflectionTypeProvider.ExceptionOccurred)
                {
                    fieldTypeName = Type.DefaultTypeNameWhenMissingMetadata;
                }
                else
                {
                    fieldTypeName = fieldType.FormatTypeName();
                }

                return(fieldTypeName + " " + this.Name);
            }
            catch
            {
                return(Type.DefaultTypeNameWhenMissingMetadata + " " + this.Name);
            }
        }
Exemple #2
0
        //
        // This is a port of the desktop CLR's RuntimeType.FormatTypeName() routine. This routine is used by various Reflection ToString() methods
        // to display the name of a type. Do not use for any other purpose as it inherits some pretty quirky desktop behavior.
        //
        // The Project N version takes a raw metadata handle rather than a completed type so that it remains robust in the face of missing metadata.
        //
        public static String FormatTypeName(this QTypeDefRefOrSpec qualifiedTypeHandle, TypeContext typeContext)
        {
            try
            {
                // Though we wrap this in a try-catch as a failsafe, this code must still strive to avoid triggering MissingMetadata exceptions
                // (non-error exceptions are very annoying when debugging.)

                Exception       exception   = null;
                RuntimeTypeInfo runtimeType = qualifiedTypeHandle.TryResolve(typeContext, ref exception);
                if (runtimeType == null)
                {
                    return(Type.DefaultTypeNameWhenMissingMetadata);
                }

                // Because this runtimeType came from a successful TryResolve() call, it is safe to querying the TypeInfo's of the type and its component parts.
                // If we're wrong, we do have the safety net of a try-catch.
                return(runtimeType.FormatTypeName());
            }
            catch (Exception)
            {
                return(Type.DefaultTypeNameWhenMissingMetadata);
            }
        }
Exemple #3
0
        //
        // This is a port of the desktop CLR's RuntimeType.FormatTypeName() routine. This routine is used by various Reflection ToString() methods
        // to display the name of a type. Do not use for any other purpose as it inherits some pretty quirky desktop behavior.
        //
        internal String FormatTypeName(TypeContext typeContext)
        {
            try
            {
                // Though we wrap this in a try-catch as a failsafe, this code must still strive to avoid triggering MissingMetadata exceptions
                // (non-error exceptions are very annoying when debugging.)

                Exception       exception   = null;
                RuntimeTypeInfo runtimeType = TryResolve(typeContext, ref exception);
                if (runtimeType == null)
                {
                    return(ToStringUtils.UnavailableType);
                }

                // Because this runtimeType came from a successful TryResolve() call, it is safe to querying the TypeInfo's of the type and its component parts.
                // If we're wrong, we do have the safety net of a try-catch.
                return(runtimeType.FormatTypeName());
            }
            catch (Exception)
            {
                return(ToStringUtils.UnavailableType);
            }
        }