Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#

Window Hiding with C#

Rate me:
Please Sign up or sign in to vote.
4.89/5 (60 votes)
26 Mar 2012CPOL 349.5K   8.6K   165  
A Window Hider program that demonstrates many C# features
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace WindowHider
{
	/// <summary>
	/// Utility class for Serialization of Objects
	/// </summary>
	public class Serializer
	{
		/// <summary>
		/// Serializes an object into a binary file
		/// </summary>
		/// <param name="Object">Object to be serialized</param>
		/// <param name="FileName">File name to serialize object into</param>
		public static void Serialize(object Object, string FileName)
		{
			//Get a binary formatter
			BinaryFormatter bformatter = new BinaryFormatter();

			//Open a file stream to a new serialization file
			Stream stream = File.Open(FileName, FileMode.Create);
            
			//Serialize the given object into the file
			bformatter.Serialize(stream, Object);

			//Close the file stream
			stream.Close();
		}
		/// <summary>
		/// Deserialize an object from a file
		/// </summary>
		/// <param name="FileName">File name to deserialize object from</param>
		/// <returns>Deserialized Object (may require casting to desired type)</returns>
		public static object Deserialize(string FileName)
		{
			//Get a binary formatter
			BinaryFormatter bformatter = new BinaryFormatter();

			//Open a file stream to the serialization file
			Stream stream = File.Open(FileName, FileMode.Open);

			//Deserialize the object from the file
			object dObject = bformatter.Deserialize(stream);
			
			//Close the file stream
			stream.Close();

			//return the deserialized object
			return dObject;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I write c#

Comments and Discussions