当前位置: 首页>>代码示例>>C#>>正文


C# ConventionBuilder.GetDeclaredAttributes方法代码示例

本文整理汇总了C#中ConventionBuilder.GetDeclaredAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# ConventionBuilder.GetDeclaredAttributes方法的具体用法?C# ConventionBuilder.GetDeclaredAttributes怎么用?C# ConventionBuilder.GetDeclaredAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConventionBuilder的用法示例。


在下文中一共展示了ConventionBuilder.GetDeclaredAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportInterfaceWithTypeOf2

        public void ExportInterfaceWithTypeOf2()
        {
            var builder = new ConventionBuilder();
            builder.ForType(typeof(CFoo)).Export((c) => c.AsContractType(typeof(IFoo)));

            var exports = builder.GetDeclaredAttributes(typeof(CFoo), typeof(CFoo).GetTypeInfo()).Where<Attribute>(e => e is ExportAttribute).Cast<ExportAttribute>();
            Assert.Equal(1, exports.Count());
            Assert.Equal(exports.First().ContractType, typeof(IFoo));
        }
开发者ID:nblumhardt,项目名称:corefx,代码行数:9,代码来源:ExportBuilderUnitTests.cs

示例2: MapType_ShouldReturnProjectedAttributesForType

        public void MapType_ShouldReturnProjectedAttributesForType()
        {
            var builder = new ConventionBuilder();

            builder.
                ForTypesDerivedFrom<IFoo>().
                Export<IFoo>();

            var fooImplAttributes = builder.GetDeclaredAttributes(typeof(FooImpl), typeof(FooImpl).GetTypeInfo());
            var fooImplWithConstructorsAttributes = builder.GetDeclaredAttributes(typeof(FooImplWithConstructors), typeof(FooImplWithConstructors).GetTypeInfo());

            var exports = new List<object>();

            exports.AddRange(fooImplAttributes);
            exports.AddRange(fooImplWithConstructorsAttributes);
            Assert.Equal(2, exports.Count);

            foreach (var exportAttribute in exports)
            {
                Assert.Equal(typeof(IFoo), ((ExportAttribute)exportAttribute).ContractType);
                Assert.Null(((ExportAttribute)exportAttribute).ContractName);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:23,代码来源:ConventionBuilderTests.cs

示例3: GetExportAttributes

 private static IEnumerable<ExportAttribute> GetExportAttributes(ConventionBuilder builder, Type type)
 {
     var list = builder.GetDeclaredAttributes(type, type.GetTypeInfo());
     return list.Cast<ExportAttribute>();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:ExportInterfacesContractExclusionTests.cs

示例4: GetImportMetadataConstraintAttribute

 private static ImportMetadataConstraintAttribute GetImportMetadataConstraintAttribute(ConventionBuilder builder)
 {
     var list = builder.GetDeclaredAttributes(typeof(FooImpl), typeof(FooImpl).GetRuntimeProperties().Where((m) => m.Name == "IFooProperty").First());
     Assert.Equal(2, list.Length);
     return list.OfType<ImportMetadataConstraintAttribute>().FirstOrDefault();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:ImportBuilderTests.cs

示例5: GetAttributeFromMember

 private static Attribute GetAttributeFromMember(ConventionBuilder builder, Type type, string member)
 {
     var pi = type.GetRuntimeProperty(member);
     var list = builder.GetDeclaredAttributes(type, pi);
     return list[0] as Attribute;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:PartBuilderOfTInheritanceTests.cs

示例6: GetSelectedConstructor

        private static ConstructorInfo GetSelectedConstructor(ConventionBuilder builder, Type type)
        {
            ConstructorInfo reply = null;
            foreach (var ci in type.GetTypeInfo().DeclaredConstructors)
            {
                var li = builder.GetDeclaredAttributes(type, ci);
                if (li.Length > 0)
                {
                    Assert.True(reply == null);                   // Fail if we got more than one constructor
                    reply = ci;
                }
            }

            return reply;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:PartBuilderOfTTests.cs

示例7: GetAttributesFromMember

 private static Attribute[] GetAttributesFromMember(ConventionBuilder builder, Type type, string member)
 {
     if (string.IsNullOrEmpty(member))
     {
         var list = builder.GetDeclaredAttributes(null, type.GetTypeInfo());
         return list;
     }
     else
     {
         var pi = type.GetRuntimeProperty(member);
         var list = builder.GetDeclaredAttributes(type, pi);
         return list;
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:14,代码来源:PartBuilderOfTTests.cs

示例8: ManuallySelectingConstructor_SelectsTheExplicitOne_IEnumerableParameterBecomesImportMany

        public void ManuallySelectingConstructor_SelectsTheExplicitOne_IEnumerableParameterBecomesImportMany()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImplWithConstructors>().SelectConstructor(param => new FooImplWithConstructors(param.Import<IEnumerable<IFoo>>()));

            var selectedConstructor = GetSelectedConstructor(builder, typeof(FooImplWithConstructors));
            Assert.NotNull(selectedConstructor);
            Assert.Equal(1, selectedConstructor.GetParameters().Length);     // Should select public FooImplWithConstructors(IEnumerable<IFoo>) { }

            var pi = selectedConstructor.GetParameters()[0];
            Assert.Equal(typeof(IEnumerable<IFoo>), pi.ParameterType);

            var attributes = builder.GetDeclaredAttributes(typeof(FooImplWithConstructors), pi);
            Assert.Equal(1, attributes.Count());
            Assert.NotNull(attributes[0] as ImportManyAttribute);

            attributes = GetAttributesFromMember(builder, typeof(FooImplWithConstructors), null);
            Assert.Equal(0, attributes.Count());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:19,代码来源:PartBuilderOfTTests.cs

示例9: ManuallySelectingConstructor_SelectsTheExplicitOne

        public void ManuallySelectingConstructor_SelectsTheExplicitOne()
        {
            var builder = new ConventionBuilder();
            builder.ForType(typeof(FooImplWithConstructors)).SelectConstructor(cis => cis.ElementAt(1));

            var selectedConstructor = GetSelectedConstructor(builder, typeof(FooImplWithConstructors));
            Assert.NotNull(selectedConstructor);
            Assert.Equal(1, selectedConstructor.GetParameters().Length);     // Should select public FooImplWithConstructors(int) { }

            var pi = selectedConstructor.GetParameters()[0];
            Assert.Equal(typeof(int), pi.ParameterType);

            var attributes = builder.GetDeclaredAttributes(typeof(FooImplWithConstructors), pi);
            Assert.Equal(1, attributes.Count());
            Assert.NotNull(attributes[0] as ImportAttribute);

            attributes = GetAttributesFromMember(builder, typeof(FooImplWithConstructors), null);
            Assert.Equal(0, attributes.Count());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:19,代码来源:PartBuilderTests.cs

示例10: GetExportMetadataAttribute

 private static ExportMetadataAttribute GetExportMetadataAttribute(ConventionBuilder builder)
 {
     var list = builder.GetDeclaredAttributes(typeof(FooImpl), typeof(FooImpl).GetTypeInfo());
     Assert.Equal(2, list.Length);
     return list[1] as ExportMetadataAttribute;
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:6,代码来源:ExportBuilderTests.cs


注:本文中的ConventionBuilder.GetDeclaredAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。