private static Attribute[] GetAttributesFromMember(ConventionBuilder builder, Type type, string member) { if (string.IsNullOrEmpty(member)) { Attribute[] list = builder.GetDeclaredAttributes(null, type.GetTypeInfo()); return(list); } else { PropertyInfo pi = type.GetRuntimeProperty(member); Attribute[] list = builder.GetDeclaredAttributes(type, pi); return(list); } }
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()); }
private static Attribute GetAttributeFromMember(ConventionBuilder builder, Type type, string member) { PropertyInfo pi = type.GetRuntimeProperty(member); Attribute[] list = builder.GetDeclaredAttributes(type, pi); return(list[0] as Attribute); }
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)); }
public void ExportInterfaceWithTypeOf2() { var builder = new ConventionBuilder(); builder.ForType(typeof(FooImpl)).Export((c) => c.AsContractType(typeof(IFoo))); Collections.Generic.IEnumerable <ExportAttribute> 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>(); IEnumerable <ExportAttribute> 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)); }
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); } }
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); } }
private static ConstructorInfo GetSelectedConstructor(ConventionBuilder builder, Type type) { ConstructorInfo reply = null; foreach (ConstructorInfo ci in type.GetTypeInfo().DeclaredConstructors) { Attribute[] 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)); ConstructorInfo selectedConstructor = GetSelectedConstructor(builder, typeof(FooImplWithConstructors)); Assert.NotNull(selectedConstructor); Assert.Equal(1, selectedConstructor.GetParameters().Length); // Should select public FooImplWithConstructors(IEnumerable<IFoo>) { } ParameterInfo pi = selectedConstructor.GetParameters()[0]; Assert.Equal(typeof(IEnumerable <IFoo>), pi.ParameterType); Attribute[] 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()); }
private static IEnumerable <ExportAttribute> GetExportAttributes(ConventionBuilder builder, Type type) { Attribute[] list = builder.GetDeclaredAttributes(type, type.GetTypeInfo()); return(list.Cast <ExportAttribute>()); }
private static ExportMetadataAttribute GetExportMetadataAttribute(ConventionBuilder builder) { Attribute[] list = builder.GetDeclaredAttributes(typeof(FooImpl), typeof(FooImpl).GetTypeInfo()); Assert.Equal(2, list.Length); return(list[1] as ExportMetadataAttribute); }
private static IEnumerable<ExportAttribute> GetExportAttributes(ConventionBuilder builder, Type type) { var list = builder.GetDeclaredAttributes(type, type.GetTypeInfo()); return list.Cast<ExportAttribute>(); }
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 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()); }
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 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 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; }
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; } }
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()); }