我想问一下是否有一个库允许在运行时生成接口的实现,并具有如下所示的一些附加功能。
假设我有这样的界面:
interface ICustomer
{
string Name {get;set;}
string IAddress { get;set; }
}
interface IAddress
{
string Street {get;set;}
}
我想做这样的事情:
ICustomer customer = someLibrary.Create<ICustomer>(bool createSubObjects)
whereCreate<T>()
方法将在运行时创建这样的实现:
class RuntimeCustomer : NotifyPropertyChanged,ICustomer
//NotifyPropertyChanged would be hand written class
{
string name;
IAddress address = new RuntimeAddress();
//if createSubObjects == false then `IAddress address = null`
public string Name
{
get { return name; }
set { SetProperty(ref name, value); }
}
public IAddress Address
{
get { return address; }
set { SetProperty(ref address, value) }
}
}
class RuntimeAddress : NotifyPropertyChanged, IAddress
{
string street;
public string Street
{
get { return street; }
set { SetProperty(ref,street, value) }
}
}
请问有什么想法吗?