问题描述
我有一个必须在类中使用 TEntity
的要求.但是,将Generics与类一起使用时,Azure函数无法正常工作.它甚至也没有显示在控制台上.但是,如果我从类声明中删除 TEntity
,它将显示在控制台中.那不支持吗?或对此有任何解决方法?我在互联网上进行了搜索,但没有找到与此相关的信息.
I have a requirement that I have to use TEntity
with the class. But Azure function not working when using Generics with class. It's not even showing on the console also. But If I remove TEntity
from class declaration it's showing in the console. So is this not supported? or is there any workaround for this? I have searched on internet but found nothing related to this.
public static class DataFilesIngestJobs<TEntity>
{
[FunctionName("IngestDataFilesScheduled")]
public static async Task RunScheduleAsync(
[TimerTrigger("%DataFiles:IngestJob:ScheduleExpressionTrigger%")] TimerInfo timer,
ExecutionContext context,
TraceWriter log)
{
await RunAsync(context, log);
}
[FunctionName("IngestDataFilesOnDemand")]
public static async Task RunOnDemandAsync(
[QueueTrigger("%DataFiles:IngestJob:OnDemandQueueNameTrigger%", Connection = "ConnectionStrings:BlobStorageAccount")] string queueItem,
ExecutionContext context,
TraceWriter log)
{
await RunAsync(context, log);
}
}
从类中删除 TEntity
时的控制台输出.
Console output on removing TEntity
from class.
推荐答案
在搜索 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;
请参见源代码.
我猜想是因为他们在调用函数方法时不知道将哪种类型用作通用参数.
I guess that's because they wouldn't know which type to use as generic parameter when calling the function method.
这篇关于为什么Azure函数不能与泛型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!