semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Enable CreateFromType/Object to work with closed generics

Open stephentoub opened this issue 1 year ago • 2 comments

https://github.com/microsoft/semantic-kernel/pull/6206#issuecomment-2107167732

stephentoub avatar May 13 '24 14:05 stephentoub

Suggest adding an example on how we can retrieve a generic in the Concepts\Functions\KernelMethod_Types.cs.

I may be trying the open generics here, but would be super nice if we could use that as well, without necessarily specifying the T at the class level.

public class MyPlugin
{
    [KernelFunction]
    public T GenericResult<T>(T input) => input;

    [KernelFunction]
    public Task<T> GenericResultAsync<T>(T input) => Task.FromResult(input);
}

rogerbarreto avatar May 13 '24 15:05 rogerbarreto

I may be trying the open generics here, but would be super nice if we could use that as well, without necessarily specifying the T at the class level.

This won't work today (even with my change) and is more complicated.

stephentoub avatar May 13 '24 16:05 stephentoub