Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# 4.0 实现通用接口的通用函数_C# 4.0_Interface_Generics - Fatal编程技术网

C# 4.0 实现通用接口的通用函数

C# 4.0 实现通用接口的通用函数,c#-4.0,interface,generics,C# 4.0,Interface,Generics,编辑示例中键入错误的属性名称 假设我们有这样的接口 public interface IBase {} public interface IItf_1: IBase {} public interface IItf_2: IBase {} public interface IItf_3: IBase {} public interface IInterfaceHolder<T>: IBase, INotifyPropertyChanged { // Changes to thi

编辑示例中键入错误的属性名称

假设我们有这样的接口

public interface IBase {}
public interface IItf_1: IBase {}
public interface IItf_2: IBase {}
public interface IItf_3: IBase {}

public interface IInterfaceHolder<T>: IBase, INotifyPropertyChanged {
  // Changes to this property caused raise of the PropertyChanged event
  bool Checked { get; set; }
  T Item { get; }
}

public interface ISomeFunnyInterface: INotifyPropertyChanged {
  IEnumerable<IInterfaceHolder<IItf_1>> Collection_1 { get; }
  IEnumerable<IInterfaceHolder<IItf_2>> Collection_2 { get; }
  IEnumerable<IInterfaceHolder<IItf_3>> Collection_3 { get; }
}

如何解决这个问题?如何在不需要为每个IInterfaceHandler编写单独的处理程序的情况下使其工作

如果您只需要一个通用的接口实现,而不是您正在做的事情,则可以通过nuget使用。它允许您对DynamicObject进行子类化,然后为其提供一个静态接口

IItf_1 test1 = Impromptu.ActLike<IItf_1>(myDynamicObject);
IItf_1 test1 = Impromptu.ActLike<IItf_1>(myDynamicObject);