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


C# ConventionBuilder.GetCustomAttributes方法代码示例

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


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

示例1: ExportInterfaceWithTypeOf1

        public void ExportInterfaceWithTypeOf1()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().Export<IFoo>();

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

示例2: MapType_ConventionSelectedConstructor

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

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

            var fooImplWithConstructorsTypeInfo = typeof(FooImplWithConstructors).GetTypeInfo();

            // necessary as BuildConventionConstructorAttributes is only called for type level query for attributes
            var constructor1 = fooImplWithConstructorsTypeInfo.DeclaredConstructors.Where(c => c.GetParameters().Length == 0).Single();
            var constructor2 = fooImplWithConstructorsTypeInfo.DeclaredConstructors.Where(c => c.GetParameters().Length == 1).Single();
            var constructor3 = fooImplWithConstructorsTypeInfo.DeclaredConstructors.Where(c => c.GetParameters().Length == 2).Single();

            Assert.Equal(0, builder.GetCustomAttributes(typeof(FooImplWithConstructors), constructor1).Count());
            Assert.Equal(0, builder.GetCustomAttributes(typeof(FooImplWithConstructors), constructor2).Count());

            var ci = constructor3;
            var attrs = builder.GetCustomAttributes(typeof(FooImplWithConstructors), ci);
            Assert.Equal(1, attrs.Count());
            Assert.Equal(typeof(ImportingConstructorAttribute), attrs.FirstOrDefault().GetType());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:23,代码来源:ConventionBuilderTests.cs


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