本文整理汇总了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));
}
示例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);
}
}
示例3: GetExportAttributes
private static IEnumerable<ExportAttribute> GetExportAttributes(ConventionBuilder builder, Type type)
{
var list = builder.GetDeclaredAttributes(type, type.GetTypeInfo());
return list.Cast<ExportAttribute>();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
}
示例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());
}
示例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());
}
示例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;
}