From 06665f9de0fe8cf4d4b2af6876336e85ed2b9270 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Mon, 14 Aug 2023 13:10:30 -0500 Subject: [PATCH 1/4] Add doc new invoker classes --- .../System/Reflection/ConstructorInvoker.cs | 53 +++++++++++++++ .../src/System/Reflection/MethodInvoker.cs | 65 +++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index 67fc0d3191975..7815710da6e71 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -11,6 +11,17 @@ namespace System.Reflection { + /// + /// Invokes the method reflected by the provided . + /// + /// + /// Used for better performance than when compatibility with that method + /// is not necessary and when the caller can cache the ConstructorInvoker instance for additional invoke calls.
+ /// Unlike , the invoke methods do not look up default values for arguments when + /// is specified. In addition, the target constructor may be inlined for performance and not + /// appear in stack traces. + ///
+ /// public sealed partial class ConstructorInvoker { private InvokeFunc_ObjSpanArgs? _invokeFunc_ObjSpanArgs; @@ -24,6 +35,17 @@ public sealed partial class ConstructorInvoker private readonly RuntimeConstructorInfo _method; private readonly bool _needsByRefStrategy; + /// + /// Creates a new instance of ConstructorInvoker. + /// + /// + /// For performance, the resulting instance should be cached for additional calls. + /// + /// The constructor that will be invoked. + /// An instance of a ConstructorInvoker. + /// + /// The is not a runtime-based method. + /// public static ConstructorInvoker Create(ConstructorInfo constructor) { ArgumentNullException.ThrowIfNull(constructor, nameof(constructor)); @@ -46,6 +68,21 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg Initialize(argumentTypes, out _strategy, out _invokerArgFlags, out _needsByRefStrategy); } + /// + /// Invokes the constructor using the specified parameters. + /// + /// + /// An instance of the class associated with the constructor. + /// + /// + /// The type that declares the method is an open generic type. + /// + /// + /// The correct number of arguments were not provided. + /// + /// + /// The calling convention or signature is not supported. + /// public object Invoke() { if (_argCount != 0) @@ -56,6 +93,11 @@ public object Invoke() return InvokeImpl(null, null, null, null); } + /// + /// The first argument for the invoked constructor. + /// + /// The arguments do not match the signature of the invoked constructor. + /// public object Invoke(object? arg1) { if (_argCount != 1) @@ -66,6 +108,8 @@ public object Invoke(object? arg1) return InvokeImpl(arg1, null, null, null); } + /// + /// The second argument for the invoked constructor. public object Invoke(object? arg1, object? arg2) { if (_argCount != 2) @@ -76,6 +120,8 @@ public object Invoke(object? arg1, object? arg2) return InvokeImpl(arg1, arg2, null, null); } + /// + /// The third argument for the invoked constructor. public object Invoke(object? arg1, object? arg2, object? arg3) { if (_argCount !=3) @@ -86,6 +132,8 @@ public object Invoke(object? arg1, object? arg2, object? arg3) return InvokeImpl(arg1, arg2, arg3, null); } + /// + /// The fourth argument for the invoked constructor. public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4) { if (_argCount != 4) @@ -137,6 +185,11 @@ private object InvokeImpl(object? arg1, object? arg2, object? arg3, object? arg4 return InvokeDirectByRef(arg1, arg2, arg3, arg4); } + /// + /// The arguments for the invoked constructor. + /// + /// The arguments do not match the signature of the invoked constructor. + /// public object Invoke(Span arguments) { int argLen = arguments.Length; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs index b5496c37c0cc8..2a9dad3b79ad3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs @@ -12,6 +12,17 @@ namespace System.Reflection { + /// + /// Invokes the method reflected by the provided . + /// + /// + /// Used for better performance than when compatibility with that method + /// is not necessary and when the caller can cache the MethodInvoker instance for additional invoke calls.
+ /// Unlike , the invoke methods do not look up default values for arguments when + /// is specified. In addition, the target method may be inlined for performance and not + /// appear in stack traces. + ///
+ /// public sealed partial class MethodInvoker { private InvokeFunc_ObjSpanArgs? _invokeFunc_ObjSpanArgs; @@ -26,6 +37,17 @@ public sealed partial class MethodInvoker private readonly bool _needsByRefStrategy; private readonly bool _isStatic; + /// + /// Creates a new instance of MethodInvoker. + /// + /// + /// For performance, the resulting instance should be cached for additional calls. + /// + /// The method that will be invoked. + /// An instance of a MethodInvoker. + /// + /// The is not a runtime-based method. + /// public static MethodInvoker Create(MethodBase method) { ArgumentNullException.ThrowIfNull(method, nameof(method)); @@ -60,6 +82,33 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) Initialize(argumentTypes, out _strategy, out _invokerArgFlags, out _needsByRefStrategy); } + /// + /// Invokes the method using the specified parameters. + /// + /// + /// The object on which to invoke the method. + /// If the method is static, this argument is ignored. + /// + /// + /// An object containing the return value of the invoked method, + /// or null if the invoked method does not have a return value. + /// + /// + /// The obj parameter is null and the method is not static. + /// + /// -or- + /// + /// The method is not declared or inherited by the class of obj. + /// + /// + /// The type that declares the method is an open generic type. + /// + /// + /// The correct number of arguments were not provided. + /// + /// + /// The calling convention or signature is not supported. + /// public object? Invoke(object? obj) { if (_argCount != 0) @@ -70,6 +119,11 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, null, null, null, null); } + /// + /// The first argument for the invoked method. + /// + /// The arguments do not match the signature of the invoked method. + /// public object? Invoke(object? obj, object? arg1) { if (_argCount != 1) @@ -80,6 +134,8 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, null, null, null); } + /// + /// The second argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2) { if (_argCount != 2) @@ -90,6 +146,8 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, arg2, null, null); } + /// + /// The third argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2, object? arg3) { if (_argCount != 3) @@ -100,6 +158,8 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, arg2, arg3, null); } + /// + /// The fourth argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2, object? arg3, object? arg4) { if (_argCount != 4) @@ -156,6 +216,11 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeDirectByRef(obj, arg1, arg2, arg3, arg4); } + /// + /// The arguments for the invoked method. + /// + /// The arguments do not match the signature of the invoked method. + /// public object? Invoke(object? obj, Span arguments) { int argLen = arguments.Length; From f960ec93b6d22f02e6d1ec6d289f4bb32c3cedc7 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Mon, 14 Aug 2023 15:33:18 -0500 Subject: [PATCH 2/4] Fix cref typo --- .../src/System/Reflection/ConstructorInvoker.cs | 2 +- .../src/System/Reflection/MethodInvoker.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index 7815710da6e71..2d03f465c5f32 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -17,7 +17,7 @@ namespace System.Reflection /// /// Used for better performance than when compatibility with that method /// is not necessary and when the caller can cache the ConstructorInvoker instance for additional invoke calls.
- /// Unlike , the invoke methods do not look up default values for arguments when + /// Unlike , the invoke methods do not look up default values for arguments when /// is specified. In addition, the target constructor may be inlined for performance and not /// appear in stack traces. ///
diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs index 2a9dad3b79ad3..e21180859a682 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs @@ -18,7 +18,7 @@ namespace System.Reflection /// /// Used for better performance than when compatibility with that method /// is not necessary and when the caller can cache the MethodInvoker instance for additional invoke calls.
- /// Unlike , the invoke methods do not look up default values for arguments when + /// Unlike , the invoke methods do not look up default values for arguments when /// is specified. In addition, the target method may be inlined for performance and not /// appear in stack traces. ///
From 2c312b8654f388db153ad37a3723a45227863fe4 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Mon, 14 Aug 2023 16:01:05 -0500 Subject: [PATCH 3/4] Misc errors --- .../System/Reflection/ConstructorInvoker.cs | 26 ++++++++++++------- .../src/System/Reflection/MethodInvoker.cs | 20 ++++++++++---- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index 2d03f465c5f32..f7308dbb72579 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -41,10 +41,10 @@ public sealed partial class ConstructorInvoker /// /// For performance, the resulting instance should be cached for additional calls. /// - /// The constructor that will be invoked. + /// The constructor that will be invoked. /// An instance of a ConstructorInvoker. /// - /// The is not a runtime-based method. + /// The is not a runtime-based method. /// public static ConstructorInvoker Create(ConstructorInfo constructor) { @@ -93,8 +93,8 @@ public object Invoke() return InvokeImpl(null, null, null, null); } - /// - /// The first argument for the invoked constructor. + /// + /// The first argument for the invoked method. /// /// The arguments do not match the signature of the invoked constructor. /// @@ -108,8 +108,9 @@ public object Invoke(object? arg1) return InvokeImpl(arg1, null, null, null); } - /// - /// The second argument for the invoked constructor. + /// + /// The first argument for the invoked method. + /// The second argument for the invoked method. public object Invoke(object? arg1, object? arg2) { if (_argCount != 2) @@ -120,8 +121,10 @@ public object Invoke(object? arg1, object? arg2) return InvokeImpl(arg1, arg2, null, null); } - /// - /// The third argument for the invoked constructor. + /// + /// The first argument for the invoked method. + /// The second argument for the invoked method. + /// The third argument for the invoked method. public object Invoke(object? arg1, object? arg2, object? arg3) { if (_argCount !=3) @@ -132,8 +135,11 @@ public object Invoke(object? arg1, object? arg2, object? arg3) return InvokeImpl(arg1, arg2, arg3, null); } - /// - /// The fourth argument for the invoked constructor. + /// + /// The first argument for the invoked method. + /// The second argument for the invoked method. + /// The third argument for the invoked method. + /// The fourth argument for the invoked method. public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4) { if (_argCount != 4) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs index e21180859a682..66a35dbd39c74 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs @@ -86,8 +86,7 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) /// Invokes the method using the specified parameters. /// /// - /// The object on which to invoke the method. - /// If the method is static, this argument is ignored. + /// The object on which to invoke the method. If the method is static, this argument is ignored. /// /// /// An object containing the return value of the invoked method, @@ -120,6 +119,7 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) } /// + /// The object on which to invoke the method. If the method is static, this argument is ignored. /// The first argument for the invoked method. /// /// The arguments do not match the signature of the invoked method. @@ -134,7 +134,9 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, null, null, null); } - /// + /// + /// The object on which to invoke the method. If the method is static, this argument is ignored. + /// The first argument for the invoked method. /// The second argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2) { @@ -146,7 +148,10 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, arg2, null, null); } - /// + /// + /// The object on which to invoke the method. If the method is static, this argument is ignored. + /// The first argument for the invoked method. + /// The second argument for the invoked method. /// The third argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2, object? arg3) { @@ -158,7 +163,11 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) return InvokeImpl(obj, arg1, arg2, arg3, null); } - /// + /// + /// The object on which to invoke the method. If the method is static, this argument is ignored. + /// The first argument for the invoked method. + /// The second argument for the invoked method. + /// The third argument for the invoked method. /// The fourth argument for the invoked method. public object? Invoke(object? obj, object? arg1, object? arg2, object? arg3, object? arg4) { @@ -217,6 +226,7 @@ private MethodInvoker(MethodBase method, RuntimeType[] argumentTypes) } /// + /// The object on which to invoke the method. If the method is static, this argument is ignored. /// The arguments for the invoked method. /// /// The arguments do not match the signature of the invoked method. From da5a6c4041c506b897e2f400bf5ecc18a1527ca7 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Mon, 14 Aug 2023 19:02:19 -0500 Subject: [PATCH 4/4] Remove arg reference in 0-arg ctor summary --- .../src/System/Reflection/ConstructorInvoker.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index f7308dbb72579..7f3c1a227e371 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -69,7 +69,7 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg } /// - /// Invokes the constructor using the specified parameters. + /// Invokes the constructor. /// /// /// An instance of the class associated with the constructor. @@ -93,6 +93,9 @@ public object Invoke() return InvokeImpl(null, null, null, null); } + /// + /// Invokes the constructor using the specified parameters. + /// /// /// The first argument for the invoked method. ///