我有一個類如何實現Action委託?
public class TextBoxConfig
{
public string Caption { get; set; }
public string FieldName { get; set; }
public int Width { get; set; }
public string Name { get; set; }
}
和另一工具類,其具有接受TextBoxConfig作爲這樣
public class Util
{
public static TextBox ApplySettings(TextBoxConfig config)
{
//Doing something
}
}
一般來說,我可以調用的Util類ApplySettings方法這樣
的參數的方法TextBoxConfig config = new TextBoxConfig();
config.Caption = "Name";
config.FieldName = "UserName"
config.Width = 20;
config.Name = "txtName";
TextBox txt = Util.ApplySettings(config);
但我想將參數傳遞給ApplySettings像這樣
TextBox txt = Util.ApplySettings(o =>
{
o.Caption = "Name";
o.FieldName = "UserName"
o.Width = 20;
o.Name = "txtName";
});
請建議我我該怎麼辦呢..
+1:回答這個問題(不管它聽起來多麼荒謬; p) – leppie
很好......謝謝Das :) –