ExpressionTreeCloner now can create shallow field-based clones of objects without a default constructor (before this, only deep clones worked); search-and-replace fix - some comments referred to something called 'propertys'; all cloners now correctly handle being passed null values (a clone of 'null' is also 'null' per definition)

git-svn-id: file:///srv/devel/repo-conversion/nusu@246 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2012-02-08 17:38:20 +00:00
parent 15300676ba
commit d091061baa
8 changed files with 167 additions and 22 deletions

View file

@ -169,7 +169,20 @@ namespace Nuclex.Support.Cloning {
);
// Give it a new instance of the type being cloned
transferExpressions.Add(Expression.Assign(clone, Expression.New(clonedType)));
MethodInfo getUninitializedObjectMethodInfo = typeof(FormatterServices).GetMethod(
"GetUninitializedObject", BindingFlags.Static | BindingFlags.Public
);
transferExpressions.Add(
Expression.Assign(
clone,
Expression.Convert(
Expression.Call(
getUninitializedObjectMethodInfo, Expression.Constant(clonedType)
),
clonedType
)
)
);
// Enumerate all of the type's fields and generate transfer expressions for each
FieldInfo[] fieldInfos = clonedType.GetFields(