c# - Serialize class from ToString method -


i using json.net serialize viewmodel:

public class viewmodel {    public int32 id { get; set; }    // other properties }  public static class viewmodelextensions {    public static ihtmlstring tojson(this viewmodel model) {      jsonserializersettings settings = new jsonserializersettings {       contractresolver = new camelcasepropertynamescontractresolver()     };      return mvchtmlstring.create(jsonconvert.serializeobject(model, settings));    } // tojson  } // viewmodelextensions 

instead of using extension model use add method tostring in viewmodel class serialize class itself?

how can this? , best option?

the default tostring virtual function should able override doing this:

override public string tostring() {     return [your format logic here]; } 

i think going for.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -