Saturday, July 7, 2012

Simple Singleton Object

This is a simple Singleton class created which I have serialized using separate serialized class and saved in a text file in encrypted form. The main reason of having separate Singleton Class object and Serialized Class object is to maintain its basic integrity and keep maintainable easy.

Reference -

To See how to serialize in encrypted form please refer to my previous implementation (link below).
Serialize singleton object to file - encrypted

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace TestNamespace
    public class SingletonClass
        string abc;
        // This is the crux of singleton implementation
        private static SingletonClass instance;
        private SingletonClass(){}
        public static SingletonClass Instance
                if (instance == null)
                    instance = new SingletonClass();
                return instance;

        // standard get and set methods
        public Version ABC
            get { return abc; }
            set { abc = value; }