public static Sha1 GetInstance() { Sha1 instance; try { instance = DoGetInstance(defaultType); } catch (Exception e) { Logger.GetInstance(typeof(Sha1)).Fatal("Instance initialization error: " + e); Logger.GetInstance(typeof(Sha1)).Info("Initializing " + typeof(DefaultSha1).FullName + "..."); instance = new DefaultSha1(); } return(instance); }
private static Sha1 DoGetInstance(Type type) { if (type == null) { throw new ArgumentException("Invalid arguments to get " + typeof(Sha1).Name + " instance"); } var key = type.FullName + "_"; Sha1 instance = null; if (Instances.ContainsKey(key)) { instance = Instances[key]; } if (instance == null) { Logger.GetInstance(typeof(Sha1)).Info("Initializing " + key + "..."); var constructor = type.GetConstructor(new Type[] { }); if (constructor != null) { instance = (Sha1)constructor.Invoke(new object[] { }); } } if (instance == null) { Logger.GetInstance(typeof(Sha1)).Info("Initializing " + typeof(DefaultSha1).FullName + "..."); instance = new DefaultSha1(); } lock (InstancesLock) { if (!Instances.ContainsKey(key)) { Instances.Add(key, instance); } } return(instance); }