#region Internal Methods
// helper method to construct the string representation of the parameter list
- internal const int MethodNameBufferSize = 100;
-
- internal static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
- {
- string comma = "";
-
- for (int i = 0; i < parameterTypes.Length; i++)
- {
- Type t = parameterTypes[i];
-
- sbParamList.Append(comma);
-
- 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)
- {
- sbParamList.Append(typeName.AsSpan().TrimEnd('&'));
- sbParamList.Append(" ByRef");
- }
- else
- {
- sbParamList.Append(typeName);
- }
-
- comma = ", ";
- }
-
- if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
- {
- sbParamList.Append(comma);
- sbParamList.Append("...");
- }
- }
-
internal virtual Type[] GetParameterTypes()
{
ParameterInfo[] paramInfo = GetParametersNoCopy();
public override string Name => GetCachedName(TypeNameKind.Name)!;
- // 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?
- internal override string FormatTypeName()
- {
- 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;
- }
-
// This method looks like an attractive inline but expands to two calls,
// neither of which can be inlined or optimized further. So block it
// from inlining.
}
#endif // FEATURE_COMINTEROP
- // This is only ever called on RuntimeType objects.
- internal virtual string FormatTypeName()
- {
- throw new NotImplementedException();
- }
-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool operator ==(Type? left, Type? right);
using System.Globalization;
using System.Diagnostics;
using System.Runtime.CompilerServices;
+using System.Text;
namespace System.Reflection
{
}
public static bool operator !=(MethodBase? left, MethodBase? right) => !(left == right);
+
+ internal const int MethodNameBufferSize = 100;
+
+ internal static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
+ {
+ string comma = "";
+
+ for (int i = 0; i < parameterTypes.Length; i++)
+ {
+ Type t = parameterTypes[i];
+
+ sbParamList.Append(comma);
+
+ 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)
+ {
+ sbParamList.Append(typeName.AsSpan().TrimEnd('&'));
+ sbParamList.Append(" ByRef");
+ }
+ else
+ {
+ sbParamList.Append(typeName);
+ }
+
+ comma = ", ";
+ }
+
+ if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
+ {
+ sbParamList.Append(comma);
+ sbParamList.Append("...");
+ }
+ }
}
}
return new SignatureGenericMethodParameterType(position);
}
+ // 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. Use only Name for all primitive types, void and TypedReference
+ // 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?
+ internal string FormatTypeName()
+ {
+ Type elementType = GetRootElementType();
+
+ if (elementType.IsPrimitive ||
+ elementType.IsNested ||
+ elementType == typeof(void) ||
+ elementType == typeof(TypedReference))
+ return Name;
+
+ return ToString();
+ }
+
public override string ToString() => "Type: " + Name; // Why do we add the "Type: " prefix?
public override bool Equals(object? o) => o == null ? false : Equals(o as Type);