-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: Expose any custom attributes on the underlying function method #8367
base: main
Are you sure you want to change the base?
.Net: Expose any custom attributes on the underlying function method #8367
Conversation
@@ -281,6 +288,7 @@ ValueTask<FunctionResult> Function(Kernel kernel, KernelFunction function, Kerne | |||
Function = Function, | |||
Name = functionName!, | |||
Description = method.GetCustomAttribute<DescriptionAttribute>(inherit: true)?.Description ?? "", | |||
Attributes = [.. Attribute.GetCustomAttributes(method, inherit: true)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only extracts attributes off the method. Possibly fine for a first pass but there's potentially value in also grabbing attributes off the plugin itself, parameters, etc.
@@ -74,6 +77,18 @@ public string Description | |||
init => this._description = value ?? string.Empty; | |||
} | |||
|
|||
/// <summary>Gets the attributes on the function.</summary> | |||
/// <remarks>If the function has no attributes, the returned list will be empty.</remarks> | |||
public IReadOnlyList<Attribute> Attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not make more sense to just expose the raw MethodInfo
instance, rather than just the attributes?
Motivation and Context
Description
Any custom attributes applied to the method wrapped as a
KernelFunction
should be available on theMetadata
property (e.g., in ASP.NET it's common to use theAuthorize
attribute for authorization scenarios, the same concept could be applied here and validated in a custom function filter).Fixes #8366.
Starting this out as a draft. If the idea/implementation looks good, I can refactor tests as needed.
Contribution Checklist