Convert() public method

Performs conversion between the two properties.
public Convert ( object source, PropertyInfo sourceProperty, object target, PropertyInfo targetProperty ) : void
source object The source.
sourceProperty System.Reflection.PropertyInfo Property in the origin.
target object The target.
targetProperty System.Reflection.PropertyInfo Property in the destination.
return void
Example #1
0
 public void ConvertTestComplex()
 {
     var target = new PropertyConverter();
     var source = new TestClassA {InnerClass = new TestClassC()};
     const string expected = "test";
     source.InnerClass.Name = expected;
     var fromProperty = typeof (TestClassA).GetProperty("InnerClass");
     var targetObject = new TestClassB {InnerClassName = "wrongstring"};
     var toProperty = typeof (TestClassB).GetProperty("InnerClassName");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.InnerClassName);
     Assert.AreEqual(expected, source.InnerClass.Name);
 }
Example #2
0
 public void ConvertTestSimple()
 {
     var target = new PropertyConverter();
     var source = new TestClassA();
     const string expected = "test";
     source.Name = expected;
     var fromProperty = typeof (TestClassA).GetProperty("Name");
     var targetObject = new TestClassB();
     targetObject.Name = "wrongstring";
     var toProperty = typeof (TestClassB).GetProperty("Name");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.Name);
     Assert.AreEqual(expected, source.Name);
 }
Example #3
0
 public void ConvertTestComplex()
 {
     PropertyConverter target = new PropertyConverter();
     TestClassA source = new TestClassA();
     source.InnerClass = new TestClassC();
     var expected = "test";
     source.InnerClass.Name = expected;
     PropertyInfo fromProperty = typeof(TestClassA).GetProperty("InnerClass");
     TestClassB targetObject = new TestClassB();
     targetObject.InnerClassName = "wrongstring";
     PropertyInfo toProperty = typeof(TestClassB).GetProperty("InnerClassName");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.InnerClassName);
     Assert.AreEqual(expected, source.InnerClass.Name);
 }
Example #4
0
 public void PropertyConverterNegativeTest()
 {
     var target = new PropertyConverter();
     var source = new TestClassA();
     var sourceProperty = source.GetType().GetProperty("InnerClass");
     var result = new TestClassB();
     var resultProperty = result.GetType().GetProperty("InnerClassCode");
     source.InnerClass = new TestClassC();
     target.Convert(
         source,
         sourceProperty,
         target,
         resultProperty,
         false);
 }