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