1
我已經創建了自己的類型的列表...(自定義類型的類在頁面底部)讓我喜歡的類型的工作就像一個列表
List<gridRecord> lgr = new List<gridRecord>();
lgr = populatedList();
我驗證與代碼波紋管列表中的每個領域...(這工作得很好!)
foreach (gridRecord gr in lgr)
{
gr.Quantity.validate();
gr.Title.validate();
gr.Pages.validate();
dt.Rows.Add(gr.Title.Value.ToString(), gr.Quantity.Value.ToString(), gr.Pages.Value.ToString());
}
不過,我會加入新gridFields到gridRecord類,並且不希望更改已驗證碼。
所以......我想能夠做這樣的事......
foreach (gridField gf in lgr)
{
gf.Validate();
}
格記錄類...
class gridRecord : Validateit
{
//Constructor
public gridRecord()
{
Quantity = new quantityField();
Title = new titleField();
Pages = new pagesField();
}
private quantityField quantity;
private titleField title;
private pagesField pages;
public quantityField Quantity
{
get { return quantity; }
set { quantity = value; }
}
public titleField Title
{
get { return title; }
set { title = value; }
}
public pagesField Pages
{
get { return pages; }
set { pages = value; }
}
public override void Validate()
{
}
}
gridField類...
class gridField : Validateit
{
public gridField()
{
Value = "---";
isValid = false;
message = "";
}
private string value;
protected bool isValid;
private string message;
public string Value
{
get { return this.value; }
set { this.value = value; }
}
public bool IsValid
{
get { return isValid; }
set { isValid = value; }
}
public string Message
{
get { return message; }
set { message = value; }
}
public override void Validate()
{
}
}
我需要使用IEnumerable
如果是的話如何?
感謝
你的代碼是真的* *難讀,因爲它是所有格式不正確。無論如何 - 是'Validateit'接口還是基類?它是否定義了「驗證」方法? – Jamiec
反映其可能。 http://stackoverflow.com/questions/737151/how-to-get-the-list-of-properties-of-a-class –
我修正了沒有正確格式化的類標題。 – user3755946