Skip to content
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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anthonypuppo
Copy link
Contributor

Motivation and Context

Description

Any custom attributes applied to the method wrapped as a KernelFunction should be available on the Metadata property (e.g., in ASP.NET it's common to use the Authorize 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

@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Aug 26, 2024
@github-actions github-actions bot changed the title Expose any custom attributes on the underlying function method .Net: Expose any custom attributes on the underlying function method Aug 26, 2024
@@ -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)],
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.Net: New Feature: Expose any custom attributes on the underlying function method
2 participants