/// <summary> /// Resolves the equivalent <see cref="IPropertyHandler{TInput, TResult}"/> object of the property. /// </summary> /// <param name="entityType">The type of the data entity.</param> /// <param name="propertyInfo">The instance of <see cref="PropertyInfo"/> to be resolved.</param> /// <returns>The equivalent <see cref="IPropertyHandler{TInput, TResult}"/> object of the property.</returns> public object Resolve(Type entityType, PropertyInfo propertyInfo) { var propertyHandler = (object)null; // Attribute var attribute = propertyInfo.GetCustomAttribute <PropertyHandlerAttribute>(); if (attribute != null) { propertyHandler = Converter.ToType <object>(Activator.CreateInstance(attribute.HandlerType)); } // Property Level if (propertyHandler == null) { propertyHandler = PropertyHandlerMapper.Get <object>(entityType, propertyInfo); } // Type Level if (propertyHandler == null) { propertyHandler = PropertyHandlerMapper.Get <object>(propertyInfo.PropertyType); } // Return the value return(propertyHandler); }
public void TestPropertyHandlerMapperTypeMappingWithoutMapping() { // Act var actual = PropertyHandlerMapper.Get <DateTime, object>(); // Assert Assert.IsNull(actual); }
public void TestPropertyHandlerMapperPropertyMappingViaExpression() { // Setup var stringPropertyHandler = new StringPropertyHandler(); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(e => e.ColumnString, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(e => e.ColumnString); var expected = stringPropertyHandler; // Assert Assert.AreEqual(expected, actual); }
public void TestPropertyHandlerMapperTypeMapping() { // Setup var stringPropertyHandler = new StringPropertyHandler(); PropertyHandlerMapper.Add <string, StringPropertyHandler>(stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <string, StringPropertyHandler>(); var expected = stringPropertyHandler; // Assert Assert.AreEqual(expected, actual); }
public void TestPropertyHandlerMapperPropertyMappingViaField() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var field = new Field("ColumnString"); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(field, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(field); var expected = stringPropertyHandler; // Assert Assert.AreEqual(expected, actual); }
public void TestPropertyHandlerMapperPropertyMappingViaPropertyName() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var propertyName = "ColumnString"; PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(propertyName, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(propertyName); var expected = stringPropertyHandler; // Assert Assert.AreEqual(expected, actual); }
public void TestPropertyHandlerMapperPropertyMappingViaExpressionOverride() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var textPropertyHandler = new TextPropertyHandler(); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(e => e.ColumnString, stringPropertyHandler); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, TextPropertyHandler>(e => e.ColumnString, textPropertyHandler, true); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, object>(e => e.ColumnString); var expected = (actual is TextPropertyHandler); // Assert Assert.IsTrue(expected); }
public void TestPropertyHandlerMapperPropertyMappingViaFieldOverride() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var textPropertyHandler = new TextPropertyHandler(); var field = new Field("ColumnString"); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(field, stringPropertyHandler); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, TextPropertyHandler>(field, textPropertyHandler, true); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, object>(field); var expected = (actual is TextPropertyHandler); // Assert Assert.IsTrue(expected); }
public void TestPropertyHandlerMapperPropertyMappingViaExpressionWithPropertyHandlerAttribute() { // Setup var stringPropertyHandler = new StringPropertyHandler(); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(e => e.PropertyString, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(e => e.PropertyString); // Assert Assert.IsNotNull(actual); // Act var textHandler = PropertyHandlerCache.Get <PropertyHandlerMapperTestClass, TextPropertyHandler>(e => e.PropertyString); // Assert Assert.IsNotNull(textHandler); }
public void TestPropertyHandlerMapperPropertyMappingViaFieldWithPropertyHandlerAttribute() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var field = new Field("PropertyString"); PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(field, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(field); // Assert Assert.IsNotNull(actual); // Act var textHandler = PropertyHandlerCache.Get <PropertyHandlerMapperTestClass, TextPropertyHandler>(field); // Assert Assert.IsNotNull(textHandler); }
public void TestPropertyHandlerMapperPropertyMappingViaPropertyNameWithPropertyHandlerAttribute() { // Setup var stringPropertyHandler = new StringPropertyHandler(); var propertyName = "PropertyString"; PropertyHandlerMapper.Add <PropertyHandlerMapperTestClass, StringPropertyHandler>(propertyName, stringPropertyHandler); // Act var actual = PropertyHandlerMapper.Get <PropertyHandlerMapperTestClass, StringPropertyHandler>(propertyName); // Assert Assert.IsNotNull(actual); // Act var textHandler = PropertyHandlerCache.Get <PropertyHandlerMapperTestClass, TextPropertyHandler>(propertyName); // Assert Assert.IsNotNull(textHandler); }
/// <summary> /// Resolves the equivalent property handler object of the .NET CLR type. /// </summary> /// <param name="type">The .NET CLR type</param> /// <returns>The equivalent property handler object of the .NET CLR type.</returns> public object Resolve(Type type) { return(PropertyHandlerMapper.Get <object>(type)); }
/// <summary> /// Resolves the equivalent <see cref="IPropertyHandler{TInput, TResult}"/> object of the .NET CLR type. /// </summary> /// <param name="type">The .NET CLR type</param> /// <returns>The equivalent <see cref="IPropertyHandler{TInput, TResult}"/> object of the .NET CLR type.</returns> public object Resolve(Type type) => PropertyHandlerMapper.Get <object>(type);