I have this code where I compare the values of oldState object by the currentState in fluent inhibernate, what I want is to log the property that has been changed and its value,here I get the new and the old values but I waant also to get the property name.
if I reflect @event.Entity I can get all the properties and their values so is there any way to get the property name by its value.
public void OnPostUpdate(NHibernate.Event.PostUpdateEvent @event)
{
var entityToAudit = @event.Entity as IAuditable;
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AuditLog.txt");
using (StreamWriter sw = File.AppendText(path))
{
for (int i = 0; i < @event.OldState.Length; i++)
{
if (@event.OldState[i] != null)
{
if (!@event.OldState[i].Equals(@event.State[i]))
{
sw.WriteLine("the value has ben changed from " + @event.OldState[i] + " to " + @event.State[i]);
}
}
else
{
if (@event.State[i] != null)
{
sw.WriteLine("the value has ben changed from being empty to " + @event.State[i]);
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire