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); } }
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); }
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); }
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()); }
public void ExportInterfaceWithTypeOf2() { var builder = new ConventionBuilder(); builder.ForType(typeof(FooImpl)).Export((c) => c.AsContractType(typeof(IFoo))); var exports = builder.GetDeclaredAttributes(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)); }
public void ExportInterfaceWithTypeOf1() { var builder = new ConventionBuilder(); builder.ForType <CFoo>().Export <IFoo>(); var exports = builder.GetDeclaredAttributes(typeof(CFoo), typeof(CFoo).GetTypeInfo()).Where <Attribute>(e => e is ExportAttribute).Cast <ExportAttribute>(); Assert.AreEqual(1, exports.Count()); Assert.AreEqual(exports.First().ContractType, typeof(IFoo)); }
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); }
public void ManuallySelectingConstructor_SelectsTheExplicitOne_IEnumerableParameterBecomesImportMany() { var builder = new ConventionBuilder(); builder.ForType(typeof(FooImplWithConstructors)).SelectConstructor(cis => cis.ElementAt(2)); 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()); }
public void ManuallySelectingConstructor_SelectsTheExplicitOne() { var builder = new ConventionBuilder(); builder.ForType <FooImplWithConstructors>().SelectConstructor(param => new FooImplWithConstructors(param.Import <int>())); var selectedConstructor = GetSelectedConstructor(builder, typeof(FooImplWithConstructors)); Assert.IsNotNull(selectedConstructor); Assert.AreEqual(1, selectedConstructor.GetParameters().Length); // Should select public FooImplWithConstructors(IEnumerable<IFoo>) { } var pi = selectedConstructor.GetParameters()[0]; Assert.AreEqual(typeof(int), pi.ParameterType); var attributes = builder.GetDeclaredAttributes(typeof(FooImplWithConstructors), pi); Assert.AreEqual(1, attributes.Count()); Assert.IsNotNull(attributes[0] as ImportAttribute); attributes = GetAttributesFromMember(builder, typeof(FooImplWithConstructors), null); Assert.AreEqual(0, attributes.Count()); }
private static IEnumerable <ExportAttribute> GetExportAttributes(ConventionBuilder builder, Type type) { var list = builder.GetDeclaredAttributes(type, type.GetTypeInfo()); return(list.Cast <ExportAttribute>()); }