2
I have a Log system that compares two generic classes and writes the name of the property and its value in a column of my database.
When the property is string, int, datetime, etc., it is saved to the database
Name:Valor
when the class property is a class for example:
public Ramal Ramal { get; set; }
is recorded at the bank Castle.Proxies.RamalProxy
. I would like to know how I can solve this (not record 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 believe this is not the case.)
Give an example of what you are trying to do. I don’t think it makes sense what you want, but maybe it’s just a matter of terminology.
– Maniero
The comments didn’t help anything, it’s all too loose, no context. It still doesn’t seem to make sense to want to know this, but show us what you do, editing the question and putting something more concrete that demonstrates the need. Maybe the solution is something else. Or you don’t even need it. So you can avoid the question being closed because it’s not clear.
– Maniero
A lot of people have shown interest in helping you. Ask yourself this question.
– Caffé
You said you are using Castle. The question should be on how to resolve a property that is being read as Proxy.
– Leonel Sanches da Silva
We now need the code you use to serialize the element for Log. It may be that you need to unclog the object inside the proxy.
– Leonel Sanches da Silva