I have a Log system that compares two generic classes and writes the property name and the value of it, in a column of my database.
When the property is of type string, int, datetime, etc., it is written to the database
Name:Valor
When the class property is a class for example:
public Ramal Ramal { get; set; }
is written to the Castle.Proxies.RamalProxy
database. I would like to know how can I fix this (do not write the proxy, but the original class).
public class Telefone
{
public string Name { get; set; }
public Ramal Ramal { get; set; }
}
public class Ramal
{
public string RamalValue { get; set; }
}
method that separates properties,
public static List<LogMessage> GetUpdateLogList<T>(T objFrom, T objTo, string[] ignore)
{
if (objFrom != null && objTo != null)
{
var type = typeof(T);
var ignoreList = new List<string>(ignore);
var unequalProperties =
from pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
where !ignoreList.Contains(pi.Name)
let propertyName = pi.Name
let selfValue = type.GetProperty(pi.Name).GetValue(objFrom, null)
let toValue = type.GetProperty(pi.Name).GetValue(objTo, null)
where selfValue != toValue && (selfValue == null || !selfValue.Equals(toValue))
select new LogMessage(propertyName.ToString()
, selfValue == null ? "null" : selfValue.ToString()
, toValue == null ? "null" : toValue.ToString()
);
List<LogMessage> logsChanged = unequalProperties.ToList();
return logsChanged;
}
where objFrom is the Original class and objTo is the modified class (I think this is not the case.)