Saturday, 15 August 2015

c# - Dynamically convert String Dictionary into Strong Typed Class Using AutoMapper -



c# - Dynamically convert String Dictionary into Strong Typed Class Using AutoMapper -

i have been searching couple of days, , have not found reply yet. case is, want fill class properties formatted string.

example :

class name : country property name : countrycode ,countryname value : 'mal' , 'malaysia'

the string : countrycode=ina&countryname=malaysia

what want type of class dynamically evaluated. utilize automapper, , code :

public class converttotype<t> { public t fillclass(string expression) { dictionary<string, string> varlist = new dictionary<string,string>(); string[] _arrayofexpression = expression.split('&'); foreach (string item in _arrayofexpression) { string _prop = item.split('=')[0]; string _val = item.split('=')[1]; if(!string.isnullorempty(_val)) varlist.add(_prop, _val); } var user = mapper.map<dictionary<string, string>, t>(varlist); homecoming user; } } country info = new country(); converttotype<country> _countryconverter = new converttotype<country>(); info = _countryconverter.fillclass(model);

with code, got error :

missing type map configuration or unsupported mapping

is there other way, or should code be?

many solution

c# asp.net-mvc automapper

No comments:

Post a Comment