ChangeTracking 2.0.22

Track changes in your POCO objects, and in your collections.

     By using Castle Dynamic Proxy to create proxies of your classes at runtime, you can use your objects just like you used do, and just by calling the AsTrackable() extension method, you get automatic change tracking, and cancellation.

There is a newer version of this package available.
See the version list below for details.
Install-Package ChangeTracking -Version 2.0.22
dotnet add package ChangeTracking --version 2.0.22
<PackageReference Include="ChangeTracking" Version="2.0.22" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChangeTracking --version 2.0.22
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Build status
NuGet Badge
Test status

ChangeTracking

Track changes in your POCO objects, and in your collections.
By using Castle Dynamic Proxy to create proxies of your classes at runtime, you can use your objects just like you used to, and just by calling the AsTrackable() extension method, you get automatic change tracking, and cancellation.

All trackable POCOs implement IChangeTrackable&lt;T&gt;, IRevertibleChangeTracking, IChangeTracking, IEditableObject and INotifyPropertyChanged.

And all trackable collections implement IChangeTrackableCollection&lt;T&gt;, IBindingList ICancelAddNew, INotifyCollectionChanged, IList&lt;T&gt;, IList, ICollection&lt;T&gt;, ICollection, IEnumerable&lt;T&gt; and IEnumerable

Installation

PM> Install-Package ChangeTracking

Example

To make an object trackable

using ChangeTracking;
//...
Order order = new Order 
{ 
    Id = 1,
    CustumerNumber = "Test",
    Address = new Address
    {
        AddressId = 1,
        City = "New York"
    },
    OrderDetails = new List<OrderDetail>
    {
        new OrderDetail
        {
            OrderDetailId = 1,
            ItemNo = "Item123"
        },
        new OrderDetail
        {
            OrderDetailId = 2,
            ItemNo = "Item369"
        }
    }
};
Order trackedOrder = order.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackable<Order>)trackedOrder;
// same as
var trackable = trackedOrder.CastToIChangeTrackable();

And here is what's available on trackable.

//Can be Unchanged, Added, Changed, Deleted
ChangeStatus status = trackable.ChangeTrackingStatus;

//Will be true if ChangeTrackingStatus is not Unchanged
bool isChanged = trackable.IsChanged;

//Will retrieve the original value of a property
string originalCustNumber = trackable.GetOriginalValue(o => o.CustumerNumber);

//Will retrieve a copy of the original item
var originalOrder = trackable.GetOriginal();

//Calling RejectChanges will reject all the changes you made, reset all properties to their original values and set ChangeTrackingStatus to Unchanged
trackable.RejectChanges();

//Calling AcceptChanges will accept all the changes you made, clears the original values and set ChangeTrackingStatus to Unchanged
trackable.AcceptChanges();

//If ChangeTrackingStatus is Changed it returns all changed property names, if ChangeTrackingStatus is Added or Deleted it returns all properties
trackable.ChangedProperties();

By default complex properties and collection properties will be tracked (if it can be made trackable) as well.
if you do not wish to track them you can set it when creating the trackable.

var trackable = order.AsTrackable(makeComplexPropertiesTrackable: false);

or

var trackable = order.AsTrackable(makeCollectionPropertiesTrackable: false);

And on a collection

var orders = new List<Order>{new Order { Id = 1, CustumerNumber = "Test" } };
IList<Order> trackableOrders = orders.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackableCollection<Order>)trackableOrders;
// Same as
var trackable = trackableOrders.CastToIChangeTrackableCollection();

And here is what's available on trackable.

// Will be true if there are any changed items, added items or deleted items in the collection.
bool isChanged = trackable.IsChanged;

// Will return all items with ChangeTrackingStatus of Unchanged
IEnumerable<Order> unchangedOrders = trackable.UnchangedItems;
// Will return all items that were added to the collection - with ChangeTrackingStatus of Added
IEnumerable<Order> addedOrders = trackable.AddedItems;
// Will return all items with ChangeTrackingStatus of Changed
IEnumerable<Order> changedOrders = trackable.ChangedItems;
// Will return all items that were removed from the collection - with ChangeTrackingStatus of Deleted
IEnumerable<Order> deletedOrders = trackable.DeletedItems;

// Will Accept all the changes in the collection and its items, deleted items will be cleared and all items ChangeTrackingStatus will be Unchanged
trackable.AcceptChanges();

// Will Reject all the changes in the collection and its items, deleted items will be moved back to the collection, added items removed and all items ChangeTrackingStatus will be Unchanged
trackable.RejectChanges();

Requirements and restrictions

  • .net 4.5.2 and above
  • netstandard 2.0
For Plain objects
  • Your class must not be sealed and all members in your class must be public virtual

    public class Order
    {
        public virtual int Id { get; set; }
        public virtual string CustumerNumber { get; set; }
        public virtual Address  Address { get; set; }
        public virtual IList<OrderDetail> OrderDetails { get; set; }
    }
    
For Collections
  • You can only assign the created proxy to one of the implemented interfaces, i.e. ICollection&lt;T&gt;, IList&lt;T&gt; and IBindingList, and the AsTrackable&lt;T&gt;() will choose the correct extennsion method only if called on IList&lt;T&gt;, IList, ICollection&lt;T&gt; and ICollection.

    IList<Order> orders = new List<Order>().AsTrackable();
    

Build status
NuGet Badge
Test status

ChangeTracking

Track changes in your POCO objects, and in your collections.
By using Castle Dynamic Proxy to create proxies of your classes at runtime, you can use your objects just like you used to, and just by calling the AsTrackable() extension method, you get automatic change tracking, and cancellation.

All trackable POCOs implement IChangeTrackable&lt;T&gt;, IRevertibleChangeTracking, IChangeTracking, IEditableObject and INotifyPropertyChanged.

And all trackable collections implement IChangeTrackableCollection&lt;T&gt;, IBindingList ICancelAddNew, INotifyCollectionChanged, IList&lt;T&gt;, IList, ICollection&lt;T&gt;, ICollection, IEnumerable&lt;T&gt; and IEnumerable

Installation

PM> Install-Package ChangeTracking

Example

To make an object trackable

using ChangeTracking;
//...
Order order = new Order 
{ 
    Id = 1,
    CustumerNumber = "Test",
    Address = new Address
    {
        AddressId = 1,
        City = "New York"
    },
    OrderDetails = new List<OrderDetail>
    {
        new OrderDetail
        {
            OrderDetailId = 1,
            ItemNo = "Item123"
        },
        new OrderDetail
        {
            OrderDetailId = 2,
            ItemNo = "Item369"
        }
    }
};
Order trackedOrder = order.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackable<Order>)trackedOrder;
// same as
var trackable = trackedOrder.CastToIChangeTrackable();

And here is what's available on trackable.

//Can be Unchanged, Added, Changed, Deleted
ChangeStatus status = trackable.ChangeTrackingStatus;

//Will be true if ChangeTrackingStatus is not Unchanged
bool isChanged = trackable.IsChanged;

//Will retrieve the original value of a property
string originalCustNumber = trackable.GetOriginalValue(o => o.CustumerNumber);

//Will retrieve a copy of the original item
var originalOrder = trackable.GetOriginal();

//Calling RejectChanges will reject all the changes you made, reset all properties to their original values and set ChangeTrackingStatus to Unchanged
trackable.RejectChanges();

//Calling AcceptChanges will accept all the changes you made, clears the original values and set ChangeTrackingStatus to Unchanged
trackable.AcceptChanges();

//If ChangeTrackingStatus is Changed it returns all changed property names, if ChangeTrackingStatus is Added or Deleted it returns all properties
trackable.ChangedProperties();

By default complex properties and collection properties will be tracked (if it can be made trackable) as well.
if you do not wish to track them you can set it when creating the trackable.

var trackable = order.AsTrackable(makeComplexPropertiesTrackable: false);

or

var trackable = order.AsTrackable(makeCollectionPropertiesTrackable: false);

And on a collection

var orders = new List<Order>{new Order { Id = 1, CustumerNumber = "Test" } };
IList<Order> trackableOrders = orders.AsTrackable();

And here is how you get to the tracked info.

var trackable = (IChangeTrackableCollection<Order>)trackableOrders;
// Same as
var trackable = trackableOrders.CastToIChangeTrackableCollection();

And here is what's available on trackable.

// Will be true if there are any changed items, added items or deleted items in the collection.
bool isChanged = trackable.IsChanged;

// Will return all items with ChangeTrackingStatus of Unchanged
IEnumerable<Order> unchangedOrders = trackable.UnchangedItems;
// Will return all items that were added to the collection - with ChangeTrackingStatus of Added
IEnumerable<Order> addedOrders = trackable.AddedItems;
// Will return all items with ChangeTrackingStatus of Changed
IEnumerable<Order> changedOrders = trackable.ChangedItems;
// Will return all items that were removed from the collection - with ChangeTrackingStatus of Deleted
IEnumerable<Order> deletedOrders = trackable.DeletedItems;

// Will Accept all the changes in the collection and its items, deleted items will be cleared and all items ChangeTrackingStatus will be Unchanged
trackable.AcceptChanges();

// Will Reject all the changes in the collection and its items, deleted items will be moved back to the collection, added items removed and all items ChangeTrackingStatus will be Unchanged
trackable.RejectChanges();

Requirements and restrictions

  • .net 4.5.2 and above
  • netstandard 2.0
For Plain objects
  • Your class must not be sealed and all members in your class must be public virtual

    public class Order
    {
        public virtual int Id { get; set; }
        public virtual string CustumerNumber { get; set; }
        public virtual Address  Address { get; set; }
        public virtual IList<OrderDetail> OrderDetails { get; set; }
    }
    
For Collections
  • You can only assign the created proxy to one of the implemented interfaces, i.e. ICollection&lt;T&gt;, IList&lt;T&gt; and IBindingList, and the AsTrackable&lt;T&gt;() will choose the correct extennsion method only if called on IList&lt;T&gt;, IList, ICollection&lt;T&gt; and ICollection.

    IList<Order> orders = new List<Order>().AsTrackable();
    

NuGet packages (4)

Showing the top 4 NuGet packages that depend on ChangeTracking:

Package Downloads
SmartLifeLtd
Official Library for Solutions The Library contains the main operations, data, utilities and Base forms for the Solutions. It's build using Visual Studio 2017, C# 7.0 and .Net framework 4.6.1 .
GoLive.Saturn.Auditing
Package Description
Ease.Repository
C#/.Net building blocks supporting implementation of the repository and unit of work patterns compatible with both NoSQL and SQL / session-aware stores. See Ease.Repository.* packages for concrete implementations.
Ease.Repository.AzureTable
C#/.Net building blocks supporting implementation of the repository and unit of work patterns for Azure Table.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.17 12,332 10/18/2019
2.2.16 567 10/4/2019
2.2.13 449 9/3/2019
2.2.4 915 7/16/2019
2.2.3 2,013 2/5/2019
2.2.2 405 1/30/2019
2.2.1 376 1/28/2019
2.2.0 401 1/24/2019
2.1.2 3,856 11/29/2018
2.1.1 507 11/1/2018
2.1.0 536 10/15/2018
2.0.22 953 9/6/2018
2.0.20 463 9/6/2018
2.0.13 1,198 7/18/2018
2.0.9 664 6/21/2018
2.0.6 3,234 5/28/2018
2.0.0 1,620 4/9/2018
2.0.0-Beta 630 1/28/2018
1.0.46 6,403 1/4/2017
1.0.44 714 12/1/2016
1.0.43 797 8/30/2016
1.0.38 1,216 10/30/2015
1.0.34 1,035 7/22/2015
1.0.26 998 11/11/2014
1.0.23 1,131 11/5/2014
1.0.22 728 10/2/2014
1.0.19 748 8/8/2014
1.0.17-beta 661 6/17/2014
1.0.16-beta 663 6/11/2014
1.0.15-beta 678 6/1/2014
0.0.9-alpha 706 5/20/2014
0.0.8-alpha 675 5/20/2014
0.0.7.2-alpha 648 5/14/2014
Show less