Exemple #1
0
        private static PropertyInfo PopularObjetoRico(Type tipoRico, string nomeCampo)
        {
            RefletorDinamico refletor = new RefletorDinamico(tipoRico);
            object           novo     = Activator.CreateInstance(tipoRico);
            PropertyInfo     pii      = refletor.Propriedade(nomeCampo, false);

            return(pii);
        }
        private static void PopulaObjetoComCampos <T>(List <string> listaCampos, RefletorDinamico refletor, T item, Dictionary <string, object> objeto, Dictionary <string, object> objetoRico)
        {
            for (int i = 0; i < listaCampos.Count; i++)
            {
                object valor;
                string propriedade = listaCampos[i];
                bool   ehRico      = false;
                if (propriedade.Contains("|"))
                {
                    ehRico = true;
                }

                try
                {
                    PropertyInfo prop = refletor.Propriedade(propriedade, ehRico);
                    if (!ehRico)
                    {
                        valor = prop.GetValue((T)item, null);
                        if (valor != null)
                        {
                            if (valor.GetType() == typeof(decimal))
                            {
                                objeto.Add(prop.Name.Replace("|", "."), valor.ToString());
                            }
                            else
                            {
                                objeto.Add(prop.Name.Replace("|", "."), valor);
                            }
                        }
                        else
                        {
                            objeto.Add(prop.Name.Replace("|", "."), valor);
                        }
                    }
                    else
                    {
                        valor = refletor.GetPropValueObjRico(propriedade.Replace("|", "."), (T)item);
                        objetoRico.Add(propriedade.Split('|').Last(), valor);

                        string nomeObjeto = propriedade.Split('|')[0];
                        if (objeto.ContainsKey(nomeObjeto))//Já Existe objeto
                        {
                            objeto[nomeObjeto] = objetoRico;
                        }
                        else//Novo objeto Rico
                        {
                            objeto.Add(nomeObjeto, objetoRico);
                        }
                    }
                }
                catch
                {
                    valor = "PROPRIEDADE NÃO EXISTE";
                    objeto.Add(propriedade.Replace("|", "."), valor);
                }
            }
        }