Click here to Skip to main content
12,358,497 members (66,444 online)
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads

Stats

273.3K views
7.4K downloads
156 bookmarked
Posted

Window Hiding with C#

, 26 Mar 2012 CPOL
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)

Share

About the Author

Taylor Wood
Web Developer
United States United States
I write c#

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 26 Mar 2012
Article Copyright 2002 by Taylor Wood
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid