开发者

What are the strange property types generated in a C# anonymous type?

开发者 https://www.devze.com 2023-02-02 08:53 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号