-1
可以說我有類與大量的冗餘特性,我想將它們存儲在列表中,詞典或任何改變對象的屬性,而將其存儲在列表
public class Foo
{
public Bar Bar1 {get;set;}
public Bar Bar2 {get;set;}
public Bar Bar3 {get;set;}
public Buzz Buzz1 {get;set;}
public Buzz Buzz2 {get;set;}
public Buzz Buzz3 {get;set;}
public void UpdateObject(Buzz newValue)
{
var dict = new List<KeyValuePair<Bar, Func<Buzz >>>()
{
new KeyValuePair<Bar, Func<Buzz>>(this.Bar1 ,()=>this.Buzz1),
new KeyValuePair<Bar, Func<Buzz>>(this.Bar2 ,() => this.Buzz2),
new KeyValuePair<Bar, Func<Buzz>>(this.Bar3 ,() => this.Buzz3)
};
foreach (var item in dict)
{
if (true)
{
var value = item.Value.Invoke();
value = newValue;
}
}
}
}
當然value
的改變,但Foo的Buzz1/2/3財產不是。我如何存儲對列表中的對象屬性的某種引用,獲取此項目並更改對象的值?