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