Azure函数:通用类型作为输入参数 [英] Azure Functions: Generic type as input parameter
问题描述
我正在寻找一种具有天蓝色函数来处理通用类型输入参数的理想方法.例如:
I am looking for ideal approach for having an azure function to handle generic type input parameter. For ex:
[FunctionName(nameof(SendToQueueActivityFunction))]
public async Task SendToQueueActivity<T>([ActivityTrigger] SendToQueueRequest<T> sendToQueueRequest)
基本上,"SendToQueueActivity"应该能够发送任何类型为T的对象.
Basically, "SendToQueueActivity" should be able to send any object of type T.
上面的代码不起作用.如果函数绑定不支持泛型,那么基于输入类型使函数表现不同的正确方法应该是什么.我正在寻找一种比使用动态"方法更简洁的实现方式.类型.
The above code doesnt work. If function binding doesnt support generics, what should be the right approach to have function behave differently based on input types. I am looking for a cleaner way of implementation than something like using "dynamic" type.
感谢您的时间和投入.
推荐答案
从Link Bryan提供的内容可以看出,Azure Function不支持通用类型.
As we can see from the Link Bryan provide, generic type is not support in Azure Function.
在搜索FunctionName属性时,WebJobs SDK显式丢弃泛型类型:
WebJobs SDK explicitly discards generic types when searching for FunctionName attribute:
return type.IsClass
&& (!type.IsAbstract || type.IsSealed)
&& type.IsPublic
&& !type.ContainsGenericParameters;
请参考源代码.
参考:
这篇关于Azure函数:通用类型作为输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!