public void Execute_Inherited_IsReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithInheritedProperyDepenency)); Assert.AreEqual(1, result.Count()); }
public void Execute_Static_IsNotReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithStaticProperty)); Assert.AreEqual(0, result.Count()); }
public void Execute_Static_IsNotReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithStaticProperty)); Assert.Empty(result); }
public void Execute_PublicGetterWithPrivateSetter_IsNotReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithDependency)); Assert.AreEqual(0, result.Count()); }
public void Execute_PublicGetterAndSetter_IsReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithPropertyDependency)); Assert.Single(result); }
public void Execute_Inherited_IsReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithInheritedProperyDepenency)); Assert.Single(result); }
public void Execute_PublicGetterAndSetter_IsReturned() { var propertySelector = new PropertySelector(); var result = propertySelector.Execute(typeof(FooWithProperyDependency)); Assert.Equal(1, result.Count()); }
/// <summary> /// Selects the property dependencies for the given <paramref name="type"/> /// that is annotated with the <see cref="InjectAttribute"/>. /// </summary> /// <param name="type">The <see cref="Type"/> for which to select the property dependencies.</param> /// <returns>A list of <see cref="PropertyDependency"/> instances that represents the property dependencies for the given <paramref name="type"/>.</returns> public override IEnumerable <PropertyDependency> Execute(Type type) { PropertyInfo[] properties = PropertySelector.Execute(type).ToArray(); foreach (PropertyInfo propertyInfo in properties) { InjectAttribute?injectAttribute = propertyInfo.GetCustomAttribute <InjectAttribute>(true); if (injectAttribute != null) { yield return(new PropertyDependency { Property = propertyInfo, ServiceName = injectAttribute.ServiceName, ServiceType = propertyInfo.PropertyType, IsRequired = true, }); } } }
/// <summary> /// Selects the property dependencies for the given <paramref name="type"/> /// that is annotated with the <see cref="InjectAttribute"/>. /// </summary> /// <param name="type">The <see cref="Type"/> for which to select the property dependencies.</param> /// <returns>A list of <see cref="PropertyDependency"/> instances that represents the property /// dependencies for the given <paramref name="type"/>.</returns> public override IEnumerable <PropertyDependency> Execute(Type type) { var properties = PropertySelector.Execute(type).Where(p => p.IsDefined(typeof(InjectAttribute), true)).ToArray(); foreach (var propertyInfo in properties) { var injectAttribute = (InjectAttribute)propertyInfo.GetCustomAttributes(typeof(InjectAttribute), true).FirstOrDefault(); if (injectAttribute != null) { yield return (new PropertyDependency { Property = propertyInfo, ServiceName = injectAttribute.ServiceName, ServiceType = propertyInfo.PropertyType, IsRequired = true }); } } }