Observe the following trivial anonymous type in C#
new { X = 5 };
The respective compiler generated code as seen in Reflector (omitting the object method overrides) is:
[CompilerGenerated]
internal sealed class <>f__AnonymousType0<<X>j__TPar>
{
// Fields
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly <X>j__TPar <X>i__Field;
// Methods
[DebuggerHidden]
public <>f__AnonymousType0(<X>j__TPar X)
{
this.<X>i__Field = X;
开发者_运维知识库 }
// Properties
public <X>j__TPar X
{
get
{
return this.<X>i__Field;
}
}
}
My question is WOE (What On Earth) is <X>j__TPar? The type is reflected nowhere in Reflector (pun intended).
<X>j__TPar is the name of the generic argument used in the <>f__AnonymousType0 type definition. A bit less readable indeed than T but guaranteed to never collide with another name.
加载中,请稍侯......
精彩评论