代码1
using System.Data;
namespace DataSync
{
public partial class DynamicParameters
{
private sealed class ParamInfo
{
public string Name {
get; set; }
public object Value {
get; set; }
public DbType? DbType {
get; set; }
}
}
}
代码2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace DataSync
{
/// <summary>
/// Snapshots an object for comparison later.
/// </summary>
public static class Snapshotter
{
/// <summary>
/// Starts the snapshot of an object by making a copy of its current state.
/// </summary>
/// <typeparam name="T">The type of object to snapshot.</typeparam>
/// <param name="obj">The object to snapshot.</param>
/// <returns>The snapshot of the object.</returns>
public static Snapshot<T> Start<T>(T obj)
{
return new Snapshot<T>(obj);
}
/// <summary>
/// A snapshot of an object's state.
/// </summary>
/// <typeparam name="T"></typeparam>
public class Snapshot<T>
{
private static Func<T, T> cloner;
private static Func<T, T, List<Change>> differ;
private readonly T memberWiseClone;
private readonly T trackedObject;
/// <summary>
/// Creates a snapshot from an object.
/// </summary>
/// <param name="original">The original object to snapshot.</param>
public Snapshot(T original)
{
memberWiseClone = Clone(original);
trackedObject = original;
}
/// <summary>
/// A holder for listing new values of changes fields and properties.
/// </summary>
public class Change
{
/// <summary>
/// The name of the field or property that changed.
/// </summary>
public string Name {
get; set; }
/// <summary>
/// The new value of the field or property.
/// </summary>
public object NewValue {
get; set; }
}
/// <summary>
/// Does a diff between the original object and the current state.
/// </summary>
/// <returns>The list of the fields changes in the object.</returns>
public DynamicParameters Diff()
{
return Diff(memberWiseClone, trackedObject);
}
private static T Clone(T myObject)
{
cloner = cloner ?? GenerateCloner();
return cloner(myObject);
}
private static DynamicParameters Diff(T original, T current)
{