Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Azure函数不使用泛型?_C#_Azure_Generics_Azure Storage_Azure Functions - Fatal编程技术网

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()
,而不是类,然后使用指定的泛型从条目函数调用它,比如so
RunAsync()
您希望运行时使用哪个具体的
tenty
类?@viveknuna没有运行时会在不知道类型的情况下运行泛型函数,因为它们无法猜测要使用的类型。控制台应用程序和ASP.NET都不会运行未知类型的函数。他们可以使用DI通过用注册类型替换依赖项来创建具体类型。