// See https://aka.ms/new-console-template for more information using PocClassPropertiesList; using System.Reflection; using System.Reflection.Metadata; /* var padrao = new List { new padraoDto { Number = "234"}, new padraoDto { Number = "754" } }; var cliente = new List { "754" }; var listaFaltando = padrao.Where(p => !cliente.Any(x => x == p.Number)).ToList(); foreach (var item in listaFaltando) { Console.WriteLine(item.Number); }*/ var y = new Teste { Nome = "ok", Valor = "2" }; var camposSelect = CamposSelect(new { Nome = "", casa = 2, Email = "" }); //await insert( // NOME | EMAIL, // new { nome = "", email = "" }); //await inserir(new { nome = "", email = "" }); foreach(var campo in camposSelect) { Console.WriteLine(campo); } static string[] CamposSelect(object atype) where T : class { if (atype == null) return new string[] { }; Type t = atype.GetType(); Type entityType = typeof(T); PropertyInfo[] entityProps = entityType.GetProperties(); PropertyInfo[] props = t.GetProperties(); List propNames = new List(); foreach (PropertyInfo prp in props) { foreach (PropertyInfo prpEntity in entityProps) { if (prp.Name == prpEntity.Name) { var nomeCampo = string.Empty; object[] attrs = prpEntity.GetCustomAttributes(true); foreach (object attr in attrs) { ColunaAttribute selectAttr = attr as ColunaAttribute; if (selectAttr != null && selectAttr.UsarSelect) { nomeCampo = string.IsNullOrEmpty(selectAttr.NomeCampo) ? prp.Name : selectAttr.NomeCampo; } } if (!string.IsNullOrEmpty(nomeCampo)) { propNames.Add(nomeCampo); break; } } } } return propNames.ToArray(); } public class Teste: Teste2 { [Coluna] public string Nome { get; set; } [Coluna("ValorAmount")] public string Valor { get; set; } } public class Teste2 { [Coluna("EMAIL_CAMPO")] public string Email { get; set; } } [System.AttributeUsage(System.AttributeTargets.Property) ] public class ColunaAttribute : System.Attribute { public string NomeCampo { get; private set; } = string.Empty; public bool UsarSelect { get; private set; } = true; public bool UsarInsert { get; private set; } = true; public bool UsarUpdate { get; private set; } = true; public ColunaAttribute() { } public ColunaAttribute(string nomeCampo = "", bool usarSelect = true, bool usarInsert = true, bool usarUpdate = true) { UsarInsert = usarInsert; NomeCampo = nomeCampo; UsarSelect = usarSelect; UsarUpdate = usarUpdate; } public ColunaAttribute(bool usarSelect = true, bool usarInsert = true, bool usarUpdate = true) { UsarInsert = usarInsert; UsarSelect = usarSelect; UsarUpdate = usarUpdate; } }