Cloners now offer their methods as static members for easy access in non-service oriented applications; began implementing the expression tree cloner
git-svn-id: file:///srv/devel/repo-conversion/nusu@228 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
961f56157e
commit
976b1ddba5
8 changed files with 323 additions and 43 deletions
|
@ -18,15 +18,13 @@ License along with this library
|
|||
*/
|
||||
#endregion
|
||||
|
||||
#if !(XBOX360 || WINDOWS_PHONE)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Nuclex.Support.Cloning {
|
||||
|
||||
#if false
|
||||
|
||||
/// <summary>An action that takes its arguments as references to a structure</summary>
|
||||
/// <typeparam name="TFirst">Type of the first argument to the method</typeparam>
|
||||
/// <typeparam name="TSecond">Type of the second argument to the method</typeparam>
|
||||
|
@ -40,7 +38,13 @@ namespace Nuclex.Support.Cloning {
|
|||
/// Cloning factory which uses expression trees to improve performance when cloning
|
||||
/// is a high-frequency action.
|
||||
/// </summary>
|
||||
public class ExpressionTreeCloneFactory : ICloneFactory {
|
||||
public class ExpressionTreeCloner : ICloneFactory {
|
||||
|
||||
/// <summary>Initializes the static members of the expression tree cloner</summary>
|
||||
static ExpressionTreeCloner() {
|
||||
shallowCloners = new ConcurrentDictionary<Type, Func<object, object>>();
|
||||
deepCloners = new ConcurrentDictionary<Type, Func<object, object>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep clone of the specified object, also creating clones of all
|
||||
|
@ -52,9 +56,10 @@ namespace Nuclex.Support.Cloning {
|
|||
/// Whether to clone the object based on its properties only
|
||||
/// </param>
|
||||
/// <returns>A deep clone of the provided object</returns>
|
||||
public TCloned DeepClone<TCloned>(TCloned objectToClone, bool usePropertyBasedClone)
|
||||
where TCloned : new() {
|
||||
throw new NotImplementedException();
|
||||
public static TCloned DeepClone<TCloned>(
|
||||
TCloned objectToClone, bool usePropertyBasedClone
|
||||
) {
|
||||
throw new NotImplementedException("Not implemented yet");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -66,11 +71,44 @@ namespace Nuclex.Support.Cloning {
|
|||
/// Whether to clone the object based on its properties only
|
||||
/// </param>
|
||||
/// <returns>A shallow clone of the provided object</returns>
|
||||
public TCloned ShallowClone<TCloned>(TCloned objectToClone, bool usePropertyBasedClone)
|
||||
where TCloned : new() {
|
||||
throw new NotImplementedException();
|
||||
public static TCloned ShallowClone<TCloned>(
|
||||
TCloned objectToClone, bool usePropertyBasedClone
|
||||
) {
|
||||
throw new NotImplementedException("Not implemented yet");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep clone of the specified object, also creating clones of all
|
||||
/// child objects being referenced
|
||||
/// </summary>
|
||||
/// <typeparam name="TCloned">Type of the object that will be cloned</typeparam>
|
||||
/// <param name="objectToClone">Object that will be cloned</param>
|
||||
/// <param name="usePropertyBasedClone">
|
||||
/// Whether to clone the object based on its properties only
|
||||
/// </param>
|
||||
/// <returns>A deep clone of the provided object</returns>
|
||||
TCloned ICloneFactory.DeepClone<TCloned>(
|
||||
TCloned objectToClone, bool usePropertyBasedClone
|
||||
) {
|
||||
return ExpressionTreeCloner.DeepClone<TCloned>(objectToClone, usePropertyBasedClone);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a shallow clone of the specified object, reusing any referenced objects
|
||||
/// </summary>
|
||||
/// <typeparam name="TCloned">Type of the object that will be cloned</typeparam>
|
||||
/// <param name="objectToClone">Object that will be cloned</param>
|
||||
/// <param name="usePropertyBasedClone">
|
||||
/// Whether to clone the object based on its properties only
|
||||
/// </param>
|
||||
/// <returns>A shallow clone of the provided object</returns>
|
||||
TCloned ICloneFactory.ShallowClone<TCloned>(
|
||||
TCloned objectToClone, bool usePropertyBasedClone
|
||||
) {
|
||||
return ExpressionTreeCloner.ShallowClone<TCloned>(objectToClone, usePropertyBasedClone);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Transfers the state of one object into another, creating clones of referenced objects
|
||||
/// </summary>
|
||||
|
@ -145,9 +183,15 @@ namespace Nuclex.Support.Cloning {
|
|||
where TCloned : class, new() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>Compiled cloners that perform shallow clone operations</summary>
|
||||
private static ConcurrentDictionary<Type, Func<object, object>> shallowCloners;
|
||||
/// <summary>Compiled cloners that perform deep clone operations</summary>
|
||||
private static ConcurrentDictionary<Type, Func<object, object>> deepCloners;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace Nuclex.Support.Cloning
|
||||
|
||||
#endif // !(XBOX360 || WINDOWS_PHONE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue