如何遍历如果我询问消息的类型和打印传递在如下(first, second, third) => new { One = first, Two = second, Three = third }
转换对象匿名类型
对象的anonymous type
的IEnumerable的,它说:<>f__AnonymousType0 3[MtApi.MtQuote,MtApi.MtQuote,MtApi.MtQuote]
//**How do I convert an object to the anonymous type?**
static void ShowAnonymousTypeMessage(object message)
{
foreach(var quote in message)
Console.WriteLine(
quote.Instrument + ": " + quote.Bid.ToString() + quote.Ask.ToString());
}
...
var pattern = observable1.And(observable2).And(observable3);
var plan = pattern.Then((first, second, third) => new { One = first, Two = second, Three = third });
var zippedSequence = Observable.When(plan);
zippedSequence.Subscribe(
ShowAnonymousTypeMessage
);
你可以设置一个断点和询问模式来查看它是什么类型,并且它是否实现IEnumerable? –
在C#<= 6中,你可以用'dynamic'来做到这一点,但这实际上并不是匿名类型的意思,而'dynamic'并不意味着将C#转换为JavaScript。如果你将它传递给一个方法,它应该有一个真正的类型。即使是一个Tuple也会是一些东西。 –
@ kevin查看原文 – Ivan