(2) EntityConvert
This stuff is imitating the product of SYSTEM.CONVERT. I didn't feel like I started, I really had a little reluctant (this Utility, which is used in this article "!
Do not believe, look at the following code (two cases only J):
Code 16: I change, I change, I change!
Public Static Class EntityConvert
{
Public Static IList Tolist (DBDataReader Rdr, Type Entity)
{
ArrayList List = New ArrayList ();
Using (RDR)
{
While (Rdr.Read ())
{
Object Obj = TOOBJECT (RDR, Entity, False);
IF (Obj! = NULL)
List.add (obj);
}
}
Return List;
}
Public Static Object TOOBJECT (DBDataReader RDR,
Type Entity, Bool Bneedread
{
Object obj = NULL;
IF (! BneedRead || rdr.read ())
{
// Create a Data Entity object
Obj = activator.createinstance (entity);
/ / Set the field data of the Data Entity object
FieldInfo [] fields = entity.getfields
Bindingflags.instance | bindingflags.public;
Foreach (FieldInfo Field in Fields)
{
String FieldName = field.name;
Object FieldValue = RDR [FieldName];
IF (FieldValue == System.dbnull.Value)
Field.SetValue (Obj, null);
Else
Field.SetValue (Obj, FieldValue);
}
IF (BneedRead &&! rdr.read ())
Rdr.close ();
}
Return Obj;
}
}
Next paragraph: http://www.9cbs.net/develop/read_article.asp? Id = 27566