Mirror changes from mono/coreclr (mono/mono#16547)
authorDotnet-GitSync-Bot <45578709+Dotnet-GitSync-Bot@users.noreply.github.com>
Mon, 2 Sep 2019 20:02:59 +0000 (13:02 -0700)
committerZoltan Varga <vargaz@gmail.com>
Mon, 2 Sep 2019 20:02:59 +0000 (16:02 -0400)
* Move FormatTypeName to Type (dotnet/coreclrmono/mono#25631)

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
* Fix for mono

Commit migrated from https://github.com/mono/mono/commit/a6b91f42951492314468e63ec7d2161baea6122b

src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeMethodInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeParameterInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimePropertyInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.cs
src/mono/netcore/System.Private.CoreLib/src/System/Type.cs

index 5e2c72a..763b4a5 100644 (file)
@@ -161,20 +161,16 @@ namespace System.Reflection
                        }
                }
 
-        string FormatNameAndSig (bool serialization)
+        string FormatNameAndSig ()
         {
             // Serialization uses ToString to resolve MethodInfo overloads.
             StringBuilder sbName = new StringBuilder(Name);
 
-            // serialization == true: use unambiguous (except for assembly name) type names to distinguish between overloads.
-            // serialization == false: use basic format to maintain backward compatibility of MethodInfo.ToString().
-            TypeNameFormatFlags format = serialization ? TypeNameFormatFlags.FormatSerialization : TypeNameFormatFlags.FormatBasic;
-
             if (IsGenericMethod)
-                sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
+                sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, TypeNameFormatFlags.FormatBasic));
 
             sbName.Append("(");
-            RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
+            RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention);
             sbName.Append(")");
 
             return sbName.ToString();
@@ -192,7 +188,7 @@ namespace System.Reflection
 
         public override String ToString() 
         {
-            return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
+            return ReturnType.FormatTypeName() + " " + FormatNameAndSig();
         }
 
                internal RuntimeModule GetRuntimeModule ()
@@ -892,7 +888,7 @@ namespace System.Reflection
                        sbName.Append ("Void ");
 
                        sbName.Append("(");
-                       RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, false);
+                       RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention);
                        sbName.Append(")");
 
                        return sbName.ToString();
index 4420cf2..2d6f842 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Reflection
                        this.marshalAs = marshalAs;
                }
 
-               internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention, bool serialization)
+               internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention)
                {
                        for (int i = 0; i < p.Length; ++i) {
                                if (i > 0)
@@ -34,12 +34,12 @@ namespace System.Reflection
 
                                Type t = p[i].ParameterType;
 
-                               string typeName = t.FormatTypeName (serialization);
+                               string typeName = t.FormatTypeName ();
 
                                // Legacy: Why use "ByRef" for by ref parameters? What language is this?
                                // VB uses "ByRef" but it should precede (not follow) the parameter name.
                                // Why don't we just use "&"?
-                               if (t.IsByRef && !serialization) {
+                               if (t.IsByRef) {
                                        sb.Append (typeName.TrimEnd (new char[] { '&' }));
                                        sb.Append (" ByRef");
                                } else {
index bf5f76f..7d43f00 100644 (file)
@@ -134,12 +134,12 @@ namespace System.Reflection
         #region Object Overrides
         public override String ToString()
         {
-            return FormatNameAndSig(false);
+            return FormatNameAndSig();
         }
 
-        private string FormatNameAndSig(bool serialization)
+        private string FormatNameAndSig()
         {
-            StringBuilder sbName = new StringBuilder(PropertyType.FormatTypeName(serialization));
+            StringBuilder sbName = new StringBuilder(PropertyType.FormatTypeName());
 
             sbName.Append(" ");
             sbName.Append(Name);
@@ -147,7 +147,7 @@ namespace System.Reflection
                        var pi = GetIndexParameters ();
                        if (pi.Length > 0) {
                                sbName.Append (" [");
-                               RuntimeParameterInfo.FormatParameters (sbName, pi, 0, serialization);
+                               RuntimeParameterInfo.FormatParameters (sbName, pi, 0);
                                sbName.Append ("]");
                        }
 
index 572dea8..190a333 100644 (file)
@@ -1704,48 +1704,6 @@ namespace System
             return !object.ReferenceEquals(left, right);
         }
 
-        #region MemberInfo Overrides
-
-        // This is used by the ToString() overrides of all reflection types. The legacy behavior has the following problems:
-        //  1. Use only Name for nested types, which can be confused with global types and generic parameters of the same name.
-        //  2. Use only Name for generic parameters, which can be confused with nested types and global types of the same name.
-        //  3. Remove the namespace ("System") for all primitive types, which is not language neutral.
-        //  4. MethodBase.ToString() use "ByRef" for byref parameters which is different than Type.ToString().
-        //  5. ConstructorInfo.ToString() outputs "Void" as the return type. Why Void?
-        // Since it could be a breaking changes to fix these legacy behaviors, we only use the better and more unambiguous format
-        // in serialization (MemberInfoSerializationHolder).
-        internal override string FormatTypeName(bool serialization)
-        {
-            if (serialization)
-            {
-                return GetCachedName(TypeNameKind.SerializationName);
-            }
-            else
-            {
-                Type elementType = GetRootElementType();
-
-                // Legacy: this doesn't make sense, why use only Name for nested types but otherwise
-                // ToString() which contains namespace.
-                if (elementType.IsNested)
-                    return Name;
-
-                string typeName = ToString();
-
-                // Legacy: why removing "System"? Is it just because C# has keywords for these types?
-                // If so why don't we change it to lower case to match the C# keyword casing?
-                if (elementType.IsPrimitive ||
-                    elementType == typeof(void) ||
-                    elementType == typeof(TypedReference))
-                {
-                    typeName = typeName.Substring(@"System.".Length);
-                }
-
-                return typeName;
-            }
-        }
-
-        #endregion
-
         #region Legacy Internal
         private void CreateInstanceCheckThis()
         {
index 2b776ed..8f45e40 100644 (file)
@@ -87,16 +87,6 @@ namespace System
 
                public static Type GetTypeFromProgID (string progID, string? server, bool throwOnError) => throw new PlatformNotSupportedException ();
 
-               internal string FormatTypeName ()
-               {
-                       return FormatTypeName (false);
-               }
-
-               internal virtual string FormatTypeName (bool serialization)
-               {
-                       throw new NotImplementedException ();
-               }
-
                internal virtual Type InternalResolve ()
                {
                        return UnderlyingSystemType;