C# 为什么Azure函数不使用泛型?
我有一个要求,我必须在课堂上使用C# 为什么Azure函数不使用泛型?,c#,azure,generics,azure-storage,azure-functions,C#,Azure,Generics,Azure Storage,Azure Functions,我有一个要求,我必须在课堂上使用tenty。但Azure函数在对类使用泛型时不起作用。它甚至没有显示在控制台上。但是如果我从类声明中删除tenty,它将显示在控制台中。那么,这是否不受支持?或者有什么解决办法吗?我在网上搜索过,但没有找到与此相关的内容 public static class DataFilesIngestJobs<TEntity> { [FunctionName("IngestDataFilesScheduled")] public static a
tenty
。但Azure函数在对类使用泛型时不起作用。它甚至没有显示在控制台上。但是如果我从类声明中删除tenty
,它将显示在控制台中。那么,这是否不受支持?或者有什么解决办法吗?我在网上搜索过,但没有找到与此相关的内容
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);
}
}
public静态类datafilessentjobs
{
[FunctionName(“IngestDataFilesScheduled”)]
公共静态异步任务RunScheduleAync(
[TimerRigger(“%DataFiles:IngestJob:ScheduleExpressionTrigger%”)TimerInfo计时器,
ExecutionContext上下文,
TraceWriter日志)
{
等待RunAsync(上下文、日志);
}
[函数名(“IngestDataFilesOnDemand”)]
公共静态异步任务RunOnDemandAsync(
[QueueTrigger(“%DataFiles:IngestJob:OnDemandQueueNameTrigger%”,Connection=“ConnectionString:BlobStorageAccount”)]字符串queueItem,
ExecutionContext上下文,
TraceWriter日志)
{
等待RunAsync(上下文、日志);
}
}
从类中移除tenty
时的控制台输出。
发现以下功能:[3/21/2018 6:52:41 AM]
MyCompany.MyProject.DataFilesIngestJobs.RunScheduleAync[3/21/2018]
上午6:52:41]MyCompany.MyProject.DataFilesIngestJobs.RunOnDemandAsync
WebJobs SDK在搜索
FunctionName
属性时显式放弃泛型类型:
return type.IsClass
&& (!type.IsAbstract || type.IsSealed)
&& type.IsPublic
&& !type.ContainsGenericParameters;
看
我猜这是因为他们在调用函数方法时不知道使用哪种类型作为泛型参数。我真的看不出您在函数中使用了tenty。也许类中有更多确实需要它的函数。但据我所知,Azure不知道您想要类的泛型类型,因此它无法调用其中的函数。@abydal我使用的是
RunAsync
中的代码,该代码使用tenty
。我可能误解了这一点,但我认为您应该将函数编写为RunAsync()
,而不是类,然后使用指定的泛型从条目函数调用它,比如soRunAsync()
您希望运行时使用哪个具体的tenty
类?@viveknuna没有运行时会在不知道类型的情况下运行泛型函数,因为它们无法猜测要使用的类型。控制台应用程序和ASP.NET都不会运行未知类型的函数。他们可以使用DI通过用注册类型替换依赖项来创建具体类型。