#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2010 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
#if !(XBOX360 || WINDOWS_PHONE)
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Nuclex.Support.Cloning {
///
/// Cloning factory which uses expression trees to improve performance when cloning
/// is a high-frequency action.
///
public partial class ExpressionTreeCloner : ICloneFactory {
/// Initializes the static members of the expression tree cloner
static ExpressionTreeCloner() {
shallowFieldBasedCloners = new ConcurrentDictionary>();
deepFieldBasedCloners = new ConcurrentDictionary>();
}
///
/// Creates a deep clone of the specified object, also creating clones of all
/// child objects being referenced
///
/// Type of the object that will be cloned
/// Object that will be cloned
///
/// Whether to clone the object based on its properties only
///
/// A deep clone of the provided object
public static TCloned DeepClone(
TCloned objectToClone, bool usePropertyBasedClone
) {
object objectToCloneAsObject = objectToClone;
if(objectToCloneAsObject == null) {
return default(TCloned);
}
if(usePropertyBasedClone) {
throw new NotImplementedException("Not implemented yet");
} else {
Func