jeudi 20 septembre 2018

Mark properties of class for reflection in C#

Hi i got this simple DTO Class

public class Clientes_mdl
{        
    public int ID_Cliente { get; set; }
    public string RazonSocial { get; set; }        

    public Enumerador_mdl CondicionIva { get; set; }
    public Nullable<Enumerador_mdl> Transporte { get; set; }
    public IEnumerable<Direcciones_view> Direcciones { get; set; }
}       

ID_Cliente and RazonSocial a data properties. Transporte and Direcciones are navigation properties to other classes.

And I use this reflection code, to get class properties names:

protected void base_UpdateCommand(IDbCommand myCommand, TEntity entity, string sWhere)
{
    var properties = (typeof(TEntity)).GetProperties().ToList();

    foreach (var prop in properties)
    {
        if (prop.Name.ToUpper() != sKeyField.ToUpper()
        {
            sProps = sProps + prop.Name + "=@" + prop.Name + ", ";                    
        }
    }
}

Now I need a way to ignore navigation properties, and get only data properties names of the class (ID_Cliente and RazonSocial). Is there any decorators I can use to do that?

Thank you!





Aucun commentaire:

Enregistrer un commentaire