0

伙计们,我有以下循环,如果是一个列表,我必须再次循环,直到这里我还好,但是在另一个循环中我遇到了问题,因为我必须在“propretyinfo”中循环,我'必须循环这个 PropretyInfo 的对象并获取这个值,我在这里尝试了一个硬解析:

(List<ItemDeMescla>)objeto.GetValue(objeto, null)

但它抛出了一个异常,知道如何解析它并工作吗?

foreach (PropertyInfo objeto in processo.GetType().GetProperties())
{
    corpoEmail += CriarLinhaEmail(objeto.Name, Convert.ToString(objeto.GetValue(processo, null)), false);

    if (objeto.PropertyType.IsGenericType && (objeto.PropertyType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.List<>)))
    {
        List<ItemDeMescla> itensMescla = (List<ItemDeMescla>)objeto.GetValue(objeto, null);
        foreach (ItemDeMescla item in itensMescla)
        {
            tabelasAux.Add(CriarTabelaInternaEmail<ItemDeMescla>(item, objeto.Name));
        }
    }
}

错误堆栈:

    at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at SACG.Services.Integracao.Integracao.Utils.MontarCorpoEmail[T](T processo, String mensagem) in c:\Projetos\Cotrijal\Branch\1.8.0.0\Cotrijal\Servicos\SACG.Services.Integracao\Integracao\Utils.cs:line 176
   at SACG.Services.Integracao.Integracao.Utils.EnviarEmail[T](T processo, Int32 codigoDaUnidade, String mensagem, String assunto) in c:\Projetos\Cotrijal\Branch\1.8.0.0\Cotrijal\Servicos\SACG.Services.Integracao\Integracao\Utils.cs:line 114
   at SACG.Services.Integracao.Integracao.IntegracaoDaExpedicao.SalvarExpedicao(ExpedicaoGraos expedicaoDto, Usuario usuarioLogado) in c:\Projetos\Cotrijal\Branch\1.8.0.0\Cotrijal\Servicos\SACG.Services.Integracao\Integracao\IntegracaoDaExpedicao.cs:line 111
   at SACG.Services.Integracao.ExpedicaoDeGraos.RegistrarExpedicao(ExpedicaoGraos expedicao) in c:\Projetos\Cotrijal\Branch\1.8.0.0\Cotrijal\Servicos\SACG.Services.Integracao\ExpedicaoDeGraos.asmx.cs:line 104
4

2 回答 2

2

尝试获取对象的值,而不是 PropertyInfo:

(List<ItemDeMescla>)objeto.GetValue(processo, null)
于 2013-04-18T13:55:19.637 回答
1

尝试

objeto.GetValue(processo, null)

代替

objeto.GetValue(objeto, null)
于 2013-04-18T13:52:01.960 回答