如何遍歷如果我詢問消息的類型和打印傳遞在如下(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