夥計們我有以下循環,如果是列表我要再次循環,直到在這裏我沒事,但在這個另一個循環內我有一個問題,因爲我要循環不是「propretyinfo」,我已經到循環在這個PropretyInfo的對象,並得到這個值,我已經嘗試了硬解析此:解析proprety信息C#
(List<ItemDeMescla>)objeto.GetValue(objeto, null)
但它拋出excepetion,任何想法如何解析它和工作?
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
它扔什麼樣的例外? – slawekwin
你試圖完成什麼? – WiiMaxx
錯誤信息會比堆棧跟蹤本身更有幫助 – slawekwin