Public static BaseEntity ReceiveEntity (DataRow dr, BaseEntity entity)
{
// Declare an instance that can be converted to the nullable type
System. ComponentModel. NullableConverter nullableDateTime = new System. ComponentModel. NullableConverter (typeof (DateTime ?));
System. ComponentModel. NullableConverter nullableDecimal = new System. ComponentModel. NullableConverter (typeof (decimal ?));
If (dr = null)
Return null;
BaseEntity baseEntity = (BaseEntity) Activator. CreateInstance (entity. GetType ());
Foreach (PropertyInfo propertyInfo in entity. GetType (). GetProperties ())
{
Try
{
If (propertyInfo. name = "NewPassword" | propertyInfo. name = "DEPT_CLASS_CODE" | propertyInfo. name = "DEPT_CODE" | propertyInfo. name = "ReadOnly ")
Continue;
If (baseEntity. GetType (). GetProperty (propertyInfo. Name). PropertyType = typeof (System. DateTime ?))
{
BaseEntity. GetType (). GetProperty (propertyInfo. Name). SetValue (baseEntity, nullableDateTime. ConvertFromString (dr [propertyInfo. Name]. ToString (), null );
}
Else if (baseEntity. GetType (). GetProperty (propertyInfo. Name). PropertyType = typeof (decimal ))
{
BaseEntity. GetType (). GetProperty (propertyInfo. Name). SetValue (baseEntity, Convert. ToDecimal (dr [propertyInfo. Name]. ToString (), null );
}
Else if (baseEntity. GetType (). GetProperty (propertyInfo. Name). PropertyType = typeof (decimal ?))
{
BaseEntity. GetType (). GetProperty (propertyInfo. Name). SetValue (baseEntity, nullableDecimal. ConvertFromString (dr [propertyInfo. Name]. ToString (), null );
}
Else
{
BaseEntity. GetType (). GetProperty (propertyInfo. Name). SetValue (baseEntity, dr [propertyInfo. Name]. ToString (), null );
}
}
Catch {}
}
Return baseEntity;
}
/// <Summary>
/// Add an object to an object set
/// </Summary>
/// <Param name = "ds"> </param>
/// <Param name = "entity"> </param>
/// <Returns> </returns>
Public static List <BaseEntity> ReceiveEntity (DataSet ds, BaseEntity entity)
{
If (! (Ds! = Null & ds. Tables. Count> 0 ))
Return null;
List <BaseEntity> entityList = new List <BaseEntity> ();
Foreach (DataRow dr in ds. Tables [0]. Rows)
{
BaseEntity baseEntity = new BaseEntity ();
BaseEntity = ReceiveEntity (dr, entity );
EntityList. Add (baseEntity );
}
Return entityList;
}
Entity generated by DataTable