https://github.com/usercode/objectchangetracking
It's a simple library to track property and collection changes in your objects.
https://github.com/usercode/objectchangetracking
csharp self-tracking-entities tracking
Last synced: 4 months ago
JSON representation
It's a simple library to track property and collection changes in your objects.
- Host: GitHub
- URL: https://github.com/usercode/objectchangetracking
- Owner: usercode
- License: mit
- Created: 2018-11-21T11:42:06.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-05-28T21:13:23.000Z (over 2 years ago)
- Last Synced: 2025-09-19T17:03:46.608Z (5 months ago)
- Topics: csharp, self-tracking-entities, tracking
- Language: C#
- Homepage:
- Size: 39.1 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ObjectChangeTracking
It's a simple library to track property and collection changes in your objects.
[](https://opensource.org/licenses/MIT)
[](https://www.nuget.org/packages/ObjectChangeTracking/)
## How to use it ##
```csharp
var customer = new Customer();
customer.Lastname = "Doe";
customer.Firstname = "Jack";
customer = customer.AsTrackable();
customer.Firstname = "John";
var trackableCustomer = (ITrackableObject)customer;
bool isChanged = trackableCustomer.IsChanged; // -> true
foreach(IPropertyChange changedProperty in trackableCustomer.ChangedProperties)
{
if(changedProperty is SimplePropertyChange simpleProperty)
{
Console.WriteLine(simpleProperty.Name); // -> "Firstname"
Console.WriteLine(simpleProperty.OldValue); // -> "Jack"
Console.WriteLine(simpleProperty.CurrentValue); // -> "John"
}
else if(changedProperty is CollectionPropertyChange collectionProperty)
{
Console.WriteLine(collectionProperty.Name);
foreach(var added in collectionProperty.Added)
{
Console.WriteLine("Added: " + added);
}
foreach(var removed in collectionProperty.Removed)
{
Console.WriteLine("Removed: " + removed);
}
}
}
```