示例#1
0
        public static Sha256 GetInstance()
        {
            Sha256 instance;

            try
            {
                instance = DoGetInstance(defaultType);
            }
            catch (Exception e)
            {
                Logger.GetInstance(typeof(Sha256)).Fatal("Instance initialization error: " + e);
                Logger.GetInstance(typeof(Sha256)).Info("Initializing " + typeof(DefaultSha256).FullName + "...");
                instance = new DefaultSha256();
            }
            return(instance);
        }
示例#2
0
        private static Sha256 DoGetInstance(Type type)
        {
            if (type == null)
            {
                throw new ArgumentException("Invalid arguments to get " + typeof(Sha256).Name + " instance");
            }

            var    key      = type.FullName + "_";
            Sha256 instance = null;

            if (Instances.ContainsKey(key))
            {
                instance = Instances[key];
            }
            if (instance == null)
            {
                Logger.GetInstance(typeof(Sha256)).Info("Initializing " + key + "...");
                var constructor = type.GetConstructor(new Type[] { });
                if (constructor != null)
                {
                    instance = (Sha256)constructor.Invoke(new object[] { });
                }
            }
            if (instance == null)
            {
                Logger.GetInstance(typeof(Sha256)).Info("Initializing " + typeof(DefaultSha256).FullName + "...");
                instance = new DefaultSha256();
            }
            lock (InstancesLock)
            {
                if (!Instances.ContainsKey(key))
                {
                    Instances.Add(key, instance);
                }
            }
            return(instance);
        }