You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.Net: Expose underlying method from kernel function (#11378)
### Motivation, Context and Description
Currently, there is no way to access the underlying method that an
instance of `KernelFunctionFromMethod` was created from or wraps. Being
able to access this underlying method is useful when additional metadata
is needed. For example, if the method has a custom attribute, you may
need to retrieve that attribute to determine the execution path.
This PR adopts the same approach as M.E.AI by exposing the native method
through the `public MethodInfo? UnderlyingMethod {...}` property. This
property is null by default and is only initialized for native functions
represented by the `KernelFunctionFromMethod` class.
Closes: #11182
---------
Co-authored-by: Roger Barreto <[email protected]>
@@ -31,11 +32,28 @@ public async Task MethodFunctionsChainingAsync()
31
32
}
32
33
33
34
/// <summary>
34
-
/// Plugin example with two method functions, where one function is called from another.
35
+
/// This example shows how to access the custom <see cref="InvocationSettingsAttribute"/> attribute the underlying method wrapped by Kernel Function is annotated with.
35
36
/// </summary>
36
-
privatesealedclassFunctionsChainingPlugin
37
+
[Fact]
38
+
publicasyncTaskAccessUnderlyingMethodAttributes()
39
+
{
40
+
// Import the plugin containing the method with the InvocationSettingsAttribute custom attribute
[RequiresUnreferencedCode("Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios.")]
425
431
[RequiresDynamicCode("Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios.")]
[RequiresUnreferencedCode("Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios.")]
450
458
[RequiresDynamicCode("Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios.")]
[UnconditionalSuppressMessage("Trimming","IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",Justification="This method is AOT save.")]
0 commit comments