Azure函数:通用类型作为输入参数 [英] Azure Functions: Generic type as input parameter

查看:55
本文介绍了Azure函数:通用类型作为输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种具有天蓝色函数来处理通用类型输入参数的理想方法.例如:

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;

请参考源代码.

参考:

  1. https://github.com/Azure/Azure-Functions/issues/735
  2. 为什么Azure函数不能与泛型一起使用?

这篇关于Azure函数:通用类型作为输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆