Tom,
I just happened to be not interested in typed datasets at all.
However! What I am suggesting is the code the typed datasets generates is
the means to "your" end!
internal MytableRow(DataRowBuilder rb) : base(rb)
{
this.tableMyTable = ((MyTableDataTable)(this.Table));
}
This is a constructor that creates a new derived DataRow based on a
DataRowBuilder, DataRowBuilder is an implementation detail that I haven't
concerned myself with (I use it where its "required" in the DataSet OM). The
constructor is internal, as its an implementation detail of the class
library, it helps enforce the "you cannot be create DataRows without using
the DataTable.NewRow method" "contract" of the DataTable. Its only part of
the picture, IMHO the important part of the"magic" is
DataTable.NewRowFromBuilder. I'm sure DataRowBuilder is simply a Parameter
Object (
http://www.refactoring.com) to pass needed information from the base
DataTable to the base DataRow during construction.
In your original post, I was under the impression you did not follow how to
get a derived DataRow to work, you "get it to work" by implementing the
NewRowFromBuilder function in a derived DataTable. The NewRowFromBuilder is
a Template Method Pattern that is used in the implementation of a
DataTable.NewRow, implementing this function enables a derived DataTable to
return type specific DataRows... The non-overridable DataTable.NewRow calls
the overridable DataTable.NewRowFromBuilder to get a type specific object
during the creation of a New DataRow, its the "out" that is required to get
a type specific row, NewRowFromBuilder also happens to be a Factory Method
(as it returns a new row).
What I don't understand here is how casting a DataSet to a MySet can work?
If you cast to a derived class does it construct a copy with the derived
members at default values?
Looking at the code of the Typed DataSet, immediately after the Clone method
there is a CreateInstance method that does return a new typed DataTable.
Seeing as the NewRow used a Template Method (NewRowFromBuilder) it does not
surprise me that it appears Clone uses a Template Method (CreateInstance). I
don't see this specifically documented! However! by putting break points in
the code, you can see when Clone is called CreateInstance is also called. If
you remove the DebuggerStepTrough attribute in the typed dataset code its
easier to single step the code...
If you cast to a derived class does it construct a copy with the derived
members at default values?
Fortunately .NET does not have this feature, you need to explicitly create
objects of the type you want, or within YOUR code implicitly use conversion
operators (which explicitly create objects). Which is where the various
Factory Method patterns are useful, especially when coupled with a Template
Method pattern. A method in a class library can define a factory/template
method that is used by derived classes to create a type specific derived
objects.
Again IMHO studying how the Typed DataSet is generated lends itself very
well how to implement derived DataTables yourself. Remember a Typed DataSet
is simply classes that are derived from DataSet, DataTable, DataRow along
with EventArgs... Seeing how the designers leverage the DataSet OM, should
help you leverage the DataSet OM...
For details on Template Method Patterns & Factory Method Patterns, I would
refer you to "Design Patterns - Elements of Reusable Object-Oriented
Software" by the GOF
(Gang of Four) Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides from
Addison Wesley Professional Computing Series
Hope this helps
Jay