コード例 #1
0
        public static UriSchemeManager GetInstance <T>() where T : UriSchemeManager
        {
            UriSchemeManager instance;

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

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

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