Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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# 如何泛化从另一个类继承的类_C#_Generics - Fatal编程技术网

C# 如何泛化从另一个类继承的类

C# 如何泛化从另一个类继承的类,c#,generics,C#,Generics,我有一个类,看起来像: public class InvokeProxy : MarshalRefByObject, IFace { public InvokeProxy(IFace face) { this.Face = face; } private IFace Face { get; set; } public string Execute(string data) { return this.Face.E

我有一个类,看起来像:

public class InvokeProxy : MarshalRefByObject, IFace
{
    public InvokeProxy(IFace face)
    {
        this.Face = face;
    }

    private IFace Face { get; set; }

    public string Execute(string data)
    {
        return this.Face.Execute(data)
    }
}

我的任务是让它通用化。由于我不能从泛型类继承,我有点卡住了,有人知道解决方法吗?

我不太确定通过将
InvokeProxy
转换为
InvokeProxy
…这有帮助吗

public class InvokeProxy<T> : MarshalRefByObject, IFace where T : IFace
{
    public InvokeProxy(T face)
    {
        this.Face = face;
    }

    private T Face { get; set; }

    public string Execute(string data)
    {
        return this.Face.Execute(data);
    }
}
public类InvokeProxy:MarshalRefByObject,IFace其中T:IFace
{
公共InvokeProxy(T面)
{
这个。脸=脸;
}
私有T面{get;set;}
公共字符串执行(字符串数据)
{
返回this.Face.Execute(数据);
}
}

我不确定我是否理解这个问题

public class InvokeProxy<T> : MarshalRefByObject where T : class
{
    public InvokeProxy(T face)
    {
        this.Face = face;
    }

    private T Face { get; set; }

    public string Execute(string data)
    {
        return this.Face.Execute(data)
    }
}
public类InvokeProxy:MarshalRefByObject其中T:class
{
公共InvokeProxy(T面)
{
这个。脸=脸;
}
私有T面{get;set;}
公共字符串执行(字符串数据)
{
返回this.Face.Execute(数据)
}
}

您希望类的哪一部分是泛型的?@cadrell0我应该让InvokeProxy类是泛型的。泛型是指InvokeProxy泛型吗?或者别的什么?好的,这里有一些东西让你开始:那就是泛型类型参数的约束。