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();
    

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.17 7,919 10/18/2019
2.2.16 479 10/4/2019
2.2.13 339 9/3/2019
2.2.4 686 7/16/2019
2.2.3 1,818 2/5/2019
2.2.2 339 1/30/2019
2.2.1 318 1/28/2019
2.2.0 350 1/24/2019
2.1.2 3,776 11/29/2018
2.1.1 442 11/1/2018
2.1.0 463 10/15/2018
2.0.22 883 9/6/2018
2.0.20 387 9/6/2018
2.0.13 1,123 7/18/2018
2.0.9 594 6/21/2018
2.0.6 3,160 5/28/2018
2.0.0 1,516 4/9/2018
2.0.0-Beta 567 1/28/2018
1.0.46 4,421 1/4/2017
1.0.44 647 12/1/2016
1.0.43 707 8/30/2016
1.0.38 1,114 10/30/2015
1.0.34 960 7/22/2015
1.0.26 933 11/11/2014
1.0.23 1,064 11/5/2014
1.0.22 663 10/2/2014
1.0.19 674 8/8/2014
1.0.17-beta 602 6/17/2014
1.0.16-beta 602 6/11/2014
1.0.15-beta 613 6/1/2014
0.0.9-alpha 641 5/20/2014
0.0.8-alpha 617 5/20/2014
0.0.7.2-alpha 580 5/14/2014
Show less