Define the entity you want to get first:
public class Inputclass {public long Id {get; set;} public int Status {get; set;} Public DateTime udpatetime {get; set;} }
converting URL parameters to corresponding dictionary types
Private dictionary<string, string> getinputnamevalues (string value) { var array = value. Split (new char[] {' & '}, stringsplitoptions.removeemptyentries); char[] split = new char[] {' = '}; dictionary<string, string> result = new dictionary<string, string> (array. Length); foreach (var item in array) { var Temparr = Item. Split (split, stringsplitoptions.removeemptyentries); if (temparr.length = = 2) { result. ADD (Temparr[0], temparr[1]); } } return result; }
To convert an entity class to a dictionary method:
Private dictionary<string, system.reflection.propertyinfo> GetProperty (type type) { var pro = type. GetProperties (); var result = new dictionary<string, propertyinfo> (pro. Length); var jsonpropertytype = typeof (Jsonpropertyattribute); foreach (var item in Pro) { var name = Item. Name; var jsonplist = (jsonpropertyattribute[]) (item. GetCustomAttributes (Jsonpropertytype, false)); if (Jsonplist.length > 0) { var jsonp = Jsonplist.first (); Jsonpropertyattribute att = new Jsonpropertyattribute (); Name = Jsonp. PropertyName; } Result. ADD (name, item); } return result; }
Main method:
var type = typeof (Inputclass); String inputstring = "id=1111&status=1&udpatetime=2015-5-9"; var model = new Inputclass (); var namevalues = getinputnamevalues (inputstring); var PropertyKeys = GetProperty (type); foreach (var item in PropertyKeys) { string value; if (Namevalues.trygetvalue (item. Key, out value)) { item. Value.setvalue (model, Convert.changetype (value, item. Value.propertytype)); } } return model;
The returned model is the encapsulated entity.
Transforming URL pass parameters into custom entity methods