Пример #1
0
        /// <summary>
        /// Find ItemType from given type representing many imports.
        /// </summary>
        /// <param name="manyType">Many imports representation.</param>
        /// <returns>ItemType if found according to MEF rules, null otherwise.</returns>
        private static TypeDescriptor findManyItemDescriptor(InheritanceChain manyType)
        {
            var signature = manyType.Path.Signature;

            if (signature == TypeDescriptor.IEnumerableSignature)
            {
                //type is IEnumerable
                return(manyType.Type.Arguments.First());
            }

            if (signature == TypeDescriptor.ArraySignature)
            {
                //type is Array
                return(manyType.Type.Arguments.First());
            }

            return(findICollectionItemDescriptor(manyType));
        }
Пример #2
0
        /// <summary>
        /// Find ItemType from given type representing many imports in ICollection{}.
        /// </summary>
        /// <param name="manyType">Many imports representation.</param>
        /// <returns>ItemType if found within ICollection according to MEF rules, null otherwise.</returns>
        private static TypeDescriptor findICollectionItemDescriptor(InheritanceChain manyType)
        {
            var signature = manyType.Path.Signature;

            if (signature == TypeDescriptor.ICollectionSignature)
            {
                //type is ICollection
                return(manyType.Type.Arguments.First());
            }

            foreach (var subchain in manyType.SubChains)
            {
                var descriptor = findICollectionItemDescriptor(subchain);
                if (descriptor != null)
                {
                    return(descriptor);
                }
            }

            return(null);
        }