コード例 #1
0
ファイル: FactoryList.cs プロジェクト: tinmanjk/NetOffice
        /// <summary>
        /// Returns contract and implementation type from given factory
        /// </summary>
        /// <param name="factory">factory to look into</param>
        /// <param name="typeId">target type id</param>
        /// <param name="contract">corresponding contract</param>
        /// <param name="implementation">corresponding implementation</param>
        /// <returns>true if both filled, otherwise false</returns>
        public bool GetContractAndImplementationType(ITypeFactory factory, Guid typeId, ref Type contract, ref Type implementation)
        {
            bool result = false;

            result = factory.ContractAndImplementation(typeId, ref contract, ref implementation);
            if (result)
            {
                var coClass = CoClassSourceAttribute.TryGet(contract, typeId);
                if (null != coClass)
                {
                    contract = coClass.Value;
                    if (!factory.Implementation(contract, ref implementation))
                    {
                        return(false);
                    }
                }
                implementation = ValidateTypeRedirection(implementation);
            }
            return(result);
        }
コード例 #2
0
ファイル: TypeDictionary.cs プロジェクト: tinmanjk/NetOffice
        /// <summary>
        /// Adds new type info to the instance
        /// </summary>
        /// <param name="factory">factory to create instances from</param>
        /// <param name="contract">contract type</param>
        /// <param name="implementation">implementation type</param>
        /// <param name="proxy">proxy type</param>
        /// <param name="componentId">component id</param>
        /// <param name="typeId">type id</param>
        /// <exception cref ="ArgumentNullException">one or more arguments is null</exception>
        /// <exception cref ="ArgumentException">one or more arguments does not match</exception>
        /// <returns>newly created typeInformation</returns>
        internal TypeInformation Add(ITypeFactory factory, Type contract, Type implementation, Type proxy, Guid componentId, Guid typeId)
        {
            if (null == factory)
            {
                throw new ArgumentNullException("factory");
            }
            if (null == contract)
            {
                throw new ArgumentNullException("contract");
            }
            if (null == implementation)
            {
                throw new ArgumentNullException("implementation");
            }
            if (null == proxy)
            {
                throw new ArgumentNullException("proxy");
            }

#if DEBUG
            if (this.Any(e => e.Contract == contract))
            {
                throw new ArgumentException("Duplicated contract in type cache detected.");
            }

            if (!factory.ContainsType(contract))
            {
                throw new ArgumentException("Factory does not support the target contract.");
            }

            if (!factory.ContainsType(implementation))
            {
                throw new ArgumentException("Factory does not support the target implementation.");
            }
#endif

            if (!contract.IsInterface)
            {
                throw new ArgumentException("contract is not an interface.");
            }
            if (implementation.IsInterface)
            {
                throw new ArgumentException("implementation must be a class.");
            }
            if (!proxy.IsCOMObject)
            {
                throw new ArgumentException("proxy must be a com object.");
            }

            TypeInformation result = null;

            var coClassSource = CoClassSourceAttribute.TryGet(contract, typeId);
            if (null != coClassSource)
            {
                contract = coClassSource.Value;
            }

            lock (_thisLock)
            {
                result = new TypeInformation(factory, contract, implementation, proxy, componentId, typeId);
                Add(result);
            }
            return(result);
        }