Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created February 27, 2013 15:59
Show Gist options
  • Save beyond-code-github/5048997 to your computer and use it in GitHub Desktop.
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
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