long lSize = 0;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter objFormatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
objFormatter.Serialize(stream, this.SalesOrder);
lSize = stream.Length;
output.Write("Size of the Object: " + lSize.ToString());
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts
Wednesday, March 25, 2009
Determining an object size in C#
I am implementing business logic for a web application that will result in a sizeable data structure being housed in a class. I may decide to cache the class in the session at some point and I wanted to know how much RAM the class takes up. To figure that out, the best way I could find (here) was to serialize it and determine the size of the resulting binary. Of course the entire class (and any classes it holds as public properties) needs to be serializable.
Wednesday, January 14, 2009
ToString()
I am always forgetting how to use ToString() to get things formatted the way I want them.
To format a datetime as a date:
To format a datetime as a date:
RequestedShipDate.ToString("d");
RequestedShipDate.ToString("MM/dd/yyyy");
Wednesday, December 3, 2008
Using Telerik RadGrid - Codebehind - Subsonic
The following code is required in to populate the grid using subsonic:
using Telerik.Web.UI;
...
protected void rgCatalogs_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
Query qry = SalesCatalog.CreateQuery();
rgCatalogs.DataSource = qry.ExecuteDataSet();
}
Monday, October 27, 2008
How to serialize an object to/from xml
I copied the below almost entirely from this page but didn't want to risk it going away before I had it committed to memory, so read that page not mine! I am not sure why you just wouldn't create a method on the object to do that but all the examples I have seen use a separate void class.
[csharp]
[csharp]
//Serialize:
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
//Deserialize:
static List<Movie> DeserializeFromXML()
{
XmlSerializer deserializer =
new XmlSerializer(typeof(List<Movie>));
TextReader textReader = new StreamReader(@"C:\movie.xml");
List<Movie> movies;
movies = (List<Movie>)deserializer.Deserialize(textReader);
textReader.Close();
return movies;
}
Subscribe to:
Posts (Atom)