本文整理汇总了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));
}
示例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());
}