Private void contructrequest (Dictionary <string, string> dictionary, customersearchrequest request)
{
For (INT I = 0; I <dictionary. Count; I ++)
{
VaR property = request. GetType (). getproperties (). firstordefault (P => P. Name = dictionary. Keys. elementat <string> (I ));
If (property = NULL) continue;
VaR propertyvalue = converttoproptype (property, dictionary. Values. elementat <string> (I ));
Property. setvalue (request, propertyvalue, null );
}
}
Handle the null type:
Public static object converttoproptype (propertyinfo property, object value)
{
Object cstval = NULL;
If (property! = NULL)
{
Type proptype = nullable. getunderlyingtype (property. propertytype );
Bool isnullable = (proptype! = NULL );
If (! Isnullable) {proptype = property. propertytype ;}
Bool canattrib = (value! = NULL | isnullable );
If (! Canattrib) {Throw new exception ("Cant attrib null on non nullable .");}
Cstval = (value = NULL | convert. isdbnull (value ))? Null: Convert. changetype (value, proptype, null );
}
Return cstval;
}