C# 一个函数如何产生多个函数?

C# 一个函数如何产生多个函数?,c#,.net,visual-studio,azure-functions,C#,.net,Visual Studio,Azure Functions,我目前正在使用Azure函数,我刚刚找到了这个接口定义 Assembly Microsoft.Extensions.Logging.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 using System; namespace Microsoft.Extensions.Logging { public interface ILogger { IDis

我目前正在使用Azure函数,我刚刚找到了这个接口定义

Assembly Microsoft.Extensions.Logging.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

using System;

namespace Microsoft.Extensions.Logging
{
    public interface ILogger
    {
        IDisposable BeginScope<TState>(TState state);

        bool IsEnabled(LogLevel logLevel);

        void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter);
    }
}
我通过Azure函数定义接收对日志的引用

[FunctionName("WhoAmI")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log)
{ ... }
[函数名(“WhoAmI”)]
公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Function,“get”,“post”,Route=null)]HttpRequestMessage请求,ILogger日志)
{ ... }
微软和微软公司也反映了这一点

我猜这是一个C#或Visual Studio功能,而不是巫术,但它是哪个功能?

这是一个称为扩展方法的C#功能。这些方法在
LoggerExtensions
static类中定义。这是一个签名示例:

public static void LogDebug (
    this ILogger logger, EventId eventId, string message, object[] args);
关键字
this
使调用看起来像是接口的成员

感谢@SirRufo在评论中给出了正确的提示。我只是不想在没有完整答案的情况下留下这个问题:)

这是一个叫做扩展方法的C#特性。这些方法在
LoggerExtensions
static类中定义。这是一个签名示例:

public static void LogDebug (
    this ILogger logger, EventId eventId, string message, object[] args);
关键字
this
使调用看起来像是接口的成员


感谢@SirRufo在评论中给出了正确的提示。我只是不想在没有完整答案的情况下留下这个问题:)

代码中
log
的引用类型是什么?@ZoharPeled,我通过Azure函数作为方法参数接收它。我对云的唯一体验就是雨。。。很抱歉也许这毕竟是巫术:-)看看那个“魔法”@SirRufo如此明显。。。我想是时候睡觉了,如果我连Azure都不知道的话…你的代码中
log
的引用类型是什么?@ZoharPeled,我通过Azure函数作为方法参数接收它。我对云的唯一体验就是雨。。。很抱歉也许这毕竟是巫术:-)看看那个“魔法”@SirRufo如此明显。。。我想是时候睡觉了,如果我在不知道Azure的情况下也无法理解它。。。