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);