简体   繁体   English

迭代列表 <int> 以匿名类型

[英]Iterating List<int> in a Anonymous Type

I am using Ninject Interception extension to implement SQLLogging. 我正在使用Ninject Interception扩展来实现SQLLogging。 I have a variable called 'param' and it is an Anonymous type as it showed in Watch window (See the picture below). 我有一个名为“ param”的变量,它是“监视”窗口中显示的匿名类型(请参见下图)。 When I do param.ToString() it returned 当我执行param.ToString()时返回

{Countries = {System.Collections.Generic.List< int >}


var param = invocation.Request.Arguments[0]; 

where invoation is of type Ninject.Extensions.Interception.IInvoation Interface. 其中发票的类型为Ninject.Extensions.Interception.IInvoation接口。

What I need to get is a name and its items. 我需要得到的是名称及其项目。 So, for this one I want something like "Countries = 36, 124, 826, 840". 因此,对于这个,我想要类似“国家= 36、124、826、840”的内容。

How do I iterate through the List to achieve that? 如何遍历列表以实现该目标? Also, notice that the name Countries in this case is not known until run-time. 另外,请注意,在这种情况下,直到运行时才知道Countries名称。 It could be something like 可能是这样的

{Ages = {System.Collections.Generic.List< int >}

or 要么

{Subjects={System.Collections.Generic.List< string >}

监视窗口中的对象

You probably want to write your own visualizer for List<T> . 您可能想为List<T>编写自己的可视化工具。 It will be used for all lists, not only the ones of your anonymous types, but it may still be useful for you. 它将用于所有列表,不仅是您的匿名类型,而且对您仍然有用。

https://msdn.microsoft.com/en-us/library/e2zc529c.aspx https://msdn.microsoft.com/zh-CN/library/e2zc529c.aspx

您可以利用反射,循环属性,检查类型,如果它是列表,则对列表进行迭代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM