对于之前的 Visual Studio 版本,可以通过编程的方式获取错误描述信息,但这些方法在 Visual Studio 2015 上已经不再适用。可使用以下代码获取所有错误列表:
dynamic selection = window.Selection;
dynamic errItems = selection.ErrorItems;
IEnumerable ienum = errItems as IEnumerable;
var enumerator = ienum.GetEnumerator();
while (enumerator.MoveNext())
{
var first = enumerator.Current;
dynamic dfirst = enumerator.Current;
object objerr = first.GetType().GetProperty("Description",typeof(string)).GetValue(first, null);
// PropertyInfo pi = first.GetType().GetProperty("Entry");//pi is null
dynamic dfirst = enumerator.Current;
// dynamic dentr = dfirst.Entry;//keeps throwing Binder exception
}
我的问题是,"Entry"属性包含另一个名为"
IsSelected
"的属性,我正在寻找它,但无法访问,就像上面注释掉的代码一样。对于我来说,动态和反射都失败了。
根据调试器,Entry属性的类型是Microsoft.VisualStudio.Shell.TableControl.Implementation.SnapshotTableEntryViewModel
,这是未记录并且很可能是VS 2015内部使用的。
我该如何访问Entry和IsSelected
属性,或者是否有其他方法只获取选定错误的描述?