Пример #1
0
        /// <summary>
        /// Add import according to given <see cref="CodeAttribute"/>
        /// </summary>
        /// <param name="importAttribute">Attribute defining import</param>
        /// <param name="forceMany">Determine that explicit <c>AllowMany</c> is used</param>
        private void addImport(AttributeInfo importAttribute, bool forceMany = false)
        {
            var builder = getOrCreateCurrentBuilder(importAttribute.Element as CodeElement);

            MethodID       importMethodID;
            TypeDescriptor importType;

            if (!getImportTarget(importAttribute.Element, builder.ComponentType, out importMethodID, out importType))
            {
                _assembly.VS.Log.Warning("Cannot parse import attribute on: " + importAttribute.Element.Name);
                return;
            }

            var explicitContract = parseContract(importAttribute.GetArgument(0), builder, importAttribute.Element);

            var allowMany    = forceMany || importAttribute.IsTrue("AllowMany");
            var allowDefault = forceMany || importAttribute.IsTrue("AllowDefault");

            var importTypeInfo = ImportTypeInfo.ParseFromMany(importType, allowMany, _services);
            var contract       = explicitContract == null ? importTypeInfo.ItemType.TypeName : explicitContract;

            builder.AddImport(importTypeInfo, importMethodID, contract, allowMany, allowDefault);
        }