public void GetPropertyAttribute_PropertyHasNoAttribute_ReturnsNull() { //Assign PropertyInfo propertyInfo = typeof(StubClassWithProperties).GetProperty("PropertyWithoutAttribute"); //Act var result = AttributeTypeLoader.GetPropertyAttribute(propertyInfo); //Assert Assert.IsNull(result); }
public void GetPropertyAttribute_PropertyHasAttribute_ReturnsAttribute() { //Assign PropertyInfo propertyInfo = typeof(StubClassWithProperties).GetProperty("PropertyWithAttribute"); //Act var result = AttributeTypeLoader.GetPropertyAttribute(propertyInfo); //Assert Assert.IsNotNull(result); Assert.IsTrue(result is StubAbstractPropertyAttribute); }
public void ProcessProperty_PropertyOnSubInterfaceWithAttribute_ReturnsConfigurationItem() { //Assign var propertyInfo = Utilities.GetProperty(typeof(StubSubInterfaceWithProperties), "PropertyWithAttribute"); //Act var result = AttributeTypeLoader.ProcessProperty(propertyInfo); //Assert Assert.IsNotNull(result); Assert.IsTrue(result is StubPropertyConfiguration); Assert.AreEqual(propertyInfo, result.PropertyInfo); }
/// <summary> /// Autoes the map properties. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public virtual IEnumerable <AbstractPropertyConfiguration> AutoMapProperties(Type type) { BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy; IEnumerable <PropertyInfo> properties = type.GetProperties(flags); if (type.IsInterface) { foreach (var inter in type.GetInterfaces()) { properties = properties.Union(inter.GetProperties(flags)); } } var propList = new List <AbstractPropertyConfiguration>(); foreach (var property in properties) { if (Properties.All(x => x.PropertyInfo != property)) { //skipped already mapped properties if (_properties.Any(x => x.PropertyInfo.Name == property.Name)) { continue; } //skip properties that are actually indexers if (property.GetIndexParameters().Length > 0) { continue; } //check for an attribute var propConfig = AttributeTypeLoader.ProcessProperty(property); if (propConfig == null) { //no attribute then automap propConfig = AutoMapProperty(property); } if (propConfig != null) { propList.Add(propConfig); } } } return(propList); }
/// <summary> /// Loads this instance. /// </summary> /// <returns> /// IEnumerable{AbstractTypeConfiguration}. /// </returns> public IEnumerable <AbstractTypeConfiguration> Load() { var loader = new AttributeTypeLoader(_type); var config = loader.Load().FirstOrDefault(); if (config == null) { config = new T(); config.Type = _type; config.ConstructorMethods = Utilities.CreateConstructorDelegates(config.Type); config.AutoMap = true; } return(new[] { config }); }
/// <summary> /// Autoes the map properties. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public virtual IEnumerable <AbstractPropertyConfiguration> AutoMapProperties(Type type) { IEnumerable <PropertyInfo> properties = Utilities.GetAllProperties(type); var propList = new List <AbstractPropertyConfiguration>(); foreach (var property in properties) { if (Properties.All(x => x.PropertyInfo != property)) { //skipped already mapped properties if (_properties.Any(x => x.PropertyInfo.Name == property.Name) || propList.Any(x => x.PropertyInfo.Name == property.Name)) { continue; } //skip properties that are actually indexers if (property.GetIndexParameters().Length > 0) { continue; } //check for an attribute var propConfig = AttributeTypeLoader.ProcessProperty(property); if (propConfig == null) { //no attribute then automap propConfig = AutoMapProperty(property); } if (propConfig != null) { propList.Add(propConfig); } } } return(propList); }