我有这个用于验证的功能
public void Validate()
{
Action<List<Field>> validateFields = (field) =>
{
if (field != null && field.Any())
{
field.ForEach(x => x.Validate());
}
};
new List<List<Field>> { this.PersonElements, this.ContactElements, this.MiscElements }.ForEach(x =>
{
try
{
validateFields(x);
}
catch (Exception e)
{
Log.ErrorFormat("An exception has occurred while validation of {1} : {0}", e, x.ToString()); // print something as x.Name.ToString());
throw;
}
});
}
问题在于这一行:
new List<List<Field>> { this.PersonElements, this.ContactElements, this.MiscElements }.ForEach(x =>
我需要(如果发生异常)将某些内容记录为
尝试处理“PersonElements / ContactElements / MiscElements”时发生异常,具体取决于发生异常的验证期间。
如果在处理过程中发生异常,如何获取列表变量名称?
提前致谢。