Created
February 27, 2013 15:59
-
-
Save beyond-code-github/5048997 to your computer and use it in GitHub Desktop.
Useful feature for Delta<T> - Get previous and current values for changed properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Dictionary<string, Tuple<object, object>> GetChanges(TEntityType original) | |
{ | |
if (original == null) | |
{ | |
throw new ArgumentNullException("original"); | |
} | |
if (!_entityType.IsAssignableFrom(original.GetType())) | |
{ | |
throw new InvalidOperationException(string.Format("Entity mismatch exception between {0} and {1}", _entityType, original.GetType())); | |
} | |
PropertyAccessor<TEntityType>[] properties = GetChangedPropertyNames().Select(s => _propertiesThatExist[s]).ToArray(); | |
return properties.ToDictionary( | |
property => property.Property.Name, | |
property => new Tuple<object, object>(property.GetValue(this._entity), property.GetValue(original))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment