【发布时间】:2010-11-29 09:52:23
【问题描述】:
我有很多实体类,现在在实体类的所有属性中都需要在getter 和setter 中添加新功能(调用某些方法)。我想说的是这样的:
public class PersistentClass : BaseClass {
private string attr1;
[Persistent]
public string Attr1
{
get
{
//need to call here base class method
//refreshContents();
return attr1;
}
set
{
//need to call here base class method
//refreshContents();
attr1 = value;
}
}
private SomeObject attr2;
[Persistent]
public SomeObject Attr2
{
get
{
//need to call here base class method
//refreshContents();
return attr2;
}
set
{
//need to call here base class method
//refreshContents();
attr2 = value;
}
}
private List<SomeOtherObhect> details;
[Persistent]
pubic List<SomeOtherObject> Details
{
get
{
//need to call here base class method
//refreshContents("details");
return details;
}
set
{
//need to call here base class method
//refreshContents("details");
details = value;
}
}
}
对于不同类型的字段,我需要调用不同的方法,例如refreshContents() 和 refreshContetns("fieldName")。我正在寻找解决 IoC 和依赖注入的问题。
你能帮帮我吗?
【问题讨论】:
-
你已经在做你想做的事了。只要您在基类中有一个 refreshContetns 方法,它就可以工作:-)
标签: c# dependency-injection ioc-container dynamic-method