///
/// Assign parameters to the specified object
///
/// Type to be assigned
/// Field/value
///
Private T Assign (Dictionary Dic) where T: new ()
{
Type t = typeof (T );
T entity = new T ();
Var fields = t. GetProperties ();
String val = string. Empty;
Object obj = null;
Foreach (var field in fields)
{
If (! Dic. Keys. Contains (field. Name ))
Continue;
Val = dic [field. Name];
// Non-generic
If (! Field. PropertyType. IsGenericType)
Obj = string. IsNullOrEmpty (val )? Null: Convert. ChangeType (val, field. PropertyType );
Else // generic Nullable <>
{
Type genericTypeDefinition = field. PropertyType. GetGenericTypeDefinition ();
If (genericTypeDefinition = typeof (Nullable <> ))
{
Obj = string. IsNullOrEmpty (val)
? Null
: Convert. ChangeType (val, Nullable. GetUnderlyingType (field. PropertyType ));
}
}
Field. SetValue (entity, obj, null );
}
Return entity;
}