public void AddPropertyCloner(PropertyInfo property, ClonerElement cloner) { propertyCloners.Add(new Tuple <PropertyInfo, ClonerElement>(property, cloner)); if (property.PropertyType == typeof(string) || property.PropertyType == typeof(int) || property.PropertyType == typeof(long) || property.PropertyType == typeof(decimal)) { // Assign primitive values directly expressions.Add( Expression.Assign( Expression.Property(outputCorrectType, property), Expression.Property(inputCorrectType, property) ) ); } else { // Everything else must be properly cloned expressions.Add( Expression.Assign( Expression.Property(outputCorrectType, property), Expression.Convert( Expression.Call( Expression.Constant(cloner), cloner.GetType().GetMethod("Clone"), Expression.Convert( Expression.Property(inputCorrectType, property), typeof(object) ) ), property.PropertyType ) ) ); } }
public ListClonerElement(ClonerElement elementCloner, Type type) { this.elementCloner = elementCloner; constructor = type.GetConstructor(new[] { typeof(int) }); }