实现多个接口的参数

Parameters implementing multiple interfaces

输入以下代码:

internal interface IHasLegs
{
    int NumberOfLegs { get; }
}

internal interface IHasName
{
    string Name { get; set; }
}

class Person : IHasLegs, IHasName
{
    public int NumberOfLegs => 2;
    public string Name { get; set; }

    public Person(string name)
    {
        Name = name;
    }
}

class Program
{
    static void ShowLegs(IHasLegs i)
    {
        Console.WriteLine($"Something has {i.NumberOfLegs} legs");
    }
    static void Main(string[] args)
    {
        Person p = new Person("Edith Piaf");

        ShowLegs(p);

        Console.ReadKey();
    }
}

有没有一种实现 ShowLegs 的方法,以便它只接受实现 IHasLegs 和 IHasName 的值,而不必声明中间 IHasLegsAndHasName: IHasLegs, IHasName ?像 ShowLegs((IHasLegs, IHasName) i) {}.

static void ShowLegs<T>(T i) where T : IHasLegs, IHasName
{
    Console.WriteLine($"{i.Name} has {i.NumberOfLegs} legs");
}