Do you know LosFormatter ?

Stoneware in the obscurity of System.WEB.UI the class LosFormatter is hiding. ASP.NET uses this class to serialize web controls state into string presentation inside hidden field inside the page Form. ASP.NET also uses LosFormatter on post back to de-serialize the hidden field back into controls. The class advantage is that it optimized for highly compact ASCII format serialization.  This class supports serializing any object graph, but is optimized for those containing strings, arrays, and hashtables.

If you have any need to serialize object into text (to transfer the object between pages, for example) you can use that class:

 

//Send Page

System.Collections.ArrayList oArr = new System.Collections.ArrayList();

oArr.Add("a");

oArr.Add("b");

oArr.Add("c");

System.Web.UI.LosFormatter oLF = new System.Web.UI.LosFormatter ();    

System.IO.StringWriter oms = new System.IO.StringWriter();

oLF.Serialize(oms,oArr);

Response.Redirect(“page1.aspx?val=” & oms.ToString());                 

//called Page

System.Collections.ArrayList oArr = new System.Collections.ArrayList();

System.Web.UI.LosFormatter oLF = new System.Web.UI.LosFormatter ();

oArr = oLF.Deserialize(Request.QueryString[“val”]) as System.Collections.ArrayList;

 

1 Comment

  • It even supports light weight encryption ... I used this class when I wrote a class that stores view state in a SQL database instead of streaming it to the client ... this saves us in a way when our viewstate is 300+k ...

Comments have been disabled for this content.