Exemplo n.º 1
0
        public void AsMany_And_ContractName_ChangesGeneratedAttributeToImportMany()
        {
            var builder = new ConventionBuilder();

            builder.ForType <FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AsContractName("hey").AsMany());

            ImportManyAttribute importAtt = GetImportManyAttribute(builder);

            Assert.NotNull(importAtt);
            Assert.Equal("hey", importAtt.ContractName);
        }
Exemplo n.º 2
0
Arquivo: MEF.cs Projeto: blqw/blqw.IOC
        /// <summary>
        /// 根据 <see cref="ImportManyAttribute" />,返回导入插件的描述信息
        /// </summary>
        /// <param name="import"> 导入描述 </param>
        /// <param name="memberType"> 属性或字段的类型 </param>
        /// <returns> </returns>
        private static ImportDefinitionImpl GetImportDefinition(ImportManyAttribute import, Type memberType)
        {
            if (import == null)
            {
                return null;
            }

            var t = import.ContractType ?? GetActualType(memberType);
            if (t == null)
            {
                return null;
            }
            var name = import.ContractName ?? AttributedModelServices.GetTypeIdentity(t);
            return new ImportDefinitionImpl(
                GetExpression(name, t),
                import.ContractName,
                ImportCardinality.ZeroOrMore,
                false,
                true,
                null)
            {
                MemberType = memberType,
                ExportedType = t
            };
        }