Пример #1
0
        /// <summary>
        /// Registers new descriptor in the factory.
        /// </summary>
        /// <param name="typeName">Object type name for the descriptor.</param>
        /// <param name="createMethod">Create descriptor method delegate.</param>
        internal void RegisterDescriptor(string typeName, CreateDescriptorMethod createMethod)
        {
            if (typeName == null)
                throw new ArgumentNullException("typeName");
            if (createMethod == null)
                throw new ArgumentNullException("createMethod");

            // Check, if descriptor already registered
            if (descriptorsDictionary.ContainsKey(typeName))
                return;
            descriptorsDictionary.Add(typeName, createMethod);
        }
Пример #2
0
        /// <summary>
        /// Returns instance of the descriptor.
        /// </summary>
        /// <param name="typeName">Object type name for the descriptor.</param>
        /// <returns>Returns instance of the descriptor.</returns>
        public IObjectDescriptor CreateDescriptor(string typeName)
        {
            // Check descriptor registration
            if (!descriptorsDictionary.ContainsKey(typeName))
            {
                return(null);
            }

            // Get create method and create instance
            CreateDescriptorMethod createMethod = descriptorsDictionary[typeName];

            if (createMethod == null)
            {
                return(null);
            }
            return(createMethod.Invoke());
        }
Пример #3
0
        /// <summary>
        /// Registers new descriptor in the factory.
        /// </summary>
        /// <param name="typeName">Object type name for the descriptor.</param>
        /// <param name="createMethod">Create descriptor method delegate.</param>
        internal void RegisterDescriptor(string typeName, CreateDescriptorMethod createMethod)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }
            if (createMethod == null)
            {
                throw new ArgumentNullException("createMethod");
            }

            // Check, if descriptor already registered
            if (descriptorsDictionary.ContainsKey(typeName))
            {
                return;
            }
            descriptorsDictionary.Add(typeName, createMethod);
        }