OK. So I understand that since you are inheriting from a dataTable the Rows are not going to be typed. So if I really wanted to have my Rows typed I would have to do something like this (which I could do everywhere by modifying a template. (But I realize this would add extra overhead, and many people would rather cast explicitly in their own code)
public new List<InvoiceInfoRow> Rows
{
get
{
List<InvoiceInfoRow> typedRows = new List<InvoiceInfoRow>();
foreach (DataRow row in base.Rows)
{
typedRows.Add((InvoiceInfoRow)row);
}
return typedRows;
}
}
However, I do wonder why you added extra code to (for instance) TypedView.Template, not only to make the fields writeable, but also to add methods so they could be written, and then add a warning that it was not advisable to use them.
public <[TypeOfTypedViewField]> <[TypedViewFieldName]>
{
get
{
if(Is<[TypedViewFieldName]>Null())
{
// return default value for this type.
return (<[TypeOfTypedViewField]>)TypeDefaultValue.GetDefaultValue(typeof(<[TypeOfTypedViewField]>));
}
else
{
return (<[TypeOfTypedViewField]>)this[_parent.<[TypedViewFieldName]>Column];
}
}
set
{
this[_parent.<[TypedViewFieldName]>Column] = value;
}
}
/// <summary>
/// Returns true if the TypedView field <[TypedViewFieldName]> is NULL, false otherwise.
/// </summary>
public bool Is<[TypedViewFieldName]>Null()
{
return IsNull(_parent.<[TypedViewFieldName]>Column);
}
/// <summary>
/// Sets the TypedView field <[TypedViewFieldName]> to NULL. Not recommended; a typed list should be used
/// as a readonly object.
/// </summary>
public void Set<[TypedViewFieldName]>Null()
{
this[_parent.<[TypedViewFieldName]>Column] = System.Convert.DBNull;
}
I thought maybe the Set****Null method might be there because you needed it yourself, but VS can't find any references to it in the generated code.
Thanks for all the information you have given.