2010-11-29 61 views
0

我有很多實體類,現在在實體類的所有屬性中需要在getters和setter中添加新的功能(調用某個方法)。我想說的是這樣的:在c動態調用方法#

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和依賴注入的問題。 你能幫我嗎?

+0

你已經在做你想做的事情了。只要你有一個refreshContetns方法到它的基類中:-) – 2010-11-29 10:09:48

回答

0

會有什麼的IoC或者DI你的情況嗎?

我覺得你只是想在基類的通用方法,並呼籲從getter方法或setter方法

0

如果你想保持你刷新邏輯在一個地方,並從您的屬性不同叫它thios法,考慮實施INotifyPropertyChanged並在實體類本身中處理PropertyChanged事件並在那裏實現刷新邏輯。

但是,更重要的問題是,爲什麼要在設置屬性或獲取屬性時刷新內容?這可能有助於瞭解您是否提供了一些不動產的名稱。