private void SetValues(string name, int dir) { BasePropertyCouple couple = null; if (_PropertyCouples.TryGetValue(name, out couple)) { if (dir > 0) { SetReflectedValues(couple.Property1Info, couple.Property2Info, _Object1, _Object2, couple, couple.Covertor1Info); } else { SetReflectedValues(couple.Property2Info, couple.Property1Info, _Object2, _Object1, couple, couple.Covertor2Info); } } }
private void SetReflectedValues(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2, object obj1, object obj2, BasePropertyCouple couple, MethodInfo covertorInfo) { object obj1Val1 = propertyInfo1.GetValue(obj1); object obj2Val1 = propertyInfo2.GetValue(obj2); lock (lockObj) { if (!obj1Val1.Equals(obj2Val1)) { if (couple.HasConverter) { object[] arguments = new object[] { obj1Val1, obj2Val1 }; covertorInfo.Invoke(couple, arguments); propertyInfo2.SetValue(obj2, arguments[1]); } else { var obj1Val1Type = obj1Val1.GetType(); propertyInfo2.SetValue(obj2, obj1Val1); /* * else * { * ConstructorInfo ctor = obj1Val1Type.GetConstructor(new[] { obj1Val1Type }); * if (ctor != null) * { * object instance = ctor.Invoke(new object[] { obj1Val1 }); * propertyInfo2.SetValue(obj2, instance); * } * else * propertyInfo2.SetValue(obj2, obj1Val1); * * }//*/ } } } }