myevh3
asked on
.NET DataRow Serialization
I'm currently trying to figure out, short of rewriting all the objects, how to make a set of objects that are based on a datarow serializable. The objects take strongly types datarows and expose the field values in the object properties:
Example:
Public string Name{
Get{
return this.DataRow.Name;
}
}
The object classes use a number of property and methods of the data row for functionality. Is there any simple changes that can be made to the struction of the class that would allow it to be serializable.
Any help would be appreciated.
Thanks,
Example:
Public string Name{
Get{
return this.DataRow.Name;
}
}
The object classes use a number of property and methods of the data row for functionality. Is there any simple changes that can be made to the struction of the class that would allow it to be serializable.
Any help would be appreciated.
Thanks,
what i could figure out of your question is that you want your datarow object to expose all of its fields in the form of properties. And this has to happen dynamically at run time as each datarow object might have different columns in it.
Well this can be done, but is quite tricky to do this.
I will refer you one code project article that helps you do this.
The concept is called Light Weight Code Generation in .net.
It allows you to dynamically add code in your objects at run time using Reflection.Emit namespace.
Please refer to the following:-
http://www.codeproject.com/KB/dotnet/Creating_Dynamic_Types.aspx
please let me know if this helped.
Well this can be done, but is quite tricky to do this.
I will refer you one code project article that helps you do this.
The concept is called Light Weight Code Generation in .net.
It allows you to dynamically add code in your objects at run time using Reflection.Emit namespace.
Please refer to the following:-
http://www.codeproject.com/KB/dotnet/Creating_Dynamic_Types.aspx
please let me know if this helped.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Only partially correct.
you can not xml-serialize DataRow as it doesn't have default constructor; but you can try the BinaryFormatter to serialize the whole object as a binary data if you want.
If it is possible in your requirment, other option is to serialize the DataTable of this DataRow and so after deserialize you can reconstruct your objects passing the DataRows