C# get set

using System;

namespace Test
{
    public class TAccount
    {
        public int FID { get; set; }
        public string FAccount { get; set; }
        public DateTime FAddtime { get; set; }
        public Guid FUniqueValue { get; set; }
        public bool IsAgent { get; set; }
    }


    public class TUserInfo
    {
        private int fid;
        public int FID { get { return fid; } set { fid = value; } }

        private string faccount;
        public string FAccount { get { return faccount; } set { faccount = value; } }

        private DateTime faddtime;
        public DateTime FAddtime { get { return faddtime; } set { faddtime = value; } }

        private Guid funiquevalue;
        public Guid FUniqueValue { get { return funiquevalue; } set { funiquevalue = value; } }

        private bool isagent;
        public bool IsAgent { get { return isagent; } set { isagent = value; } }
    }
}

//IL

 

 

public class TAccount 

.class public auto ansi beforefieldinit Test.TAccount
    extends [mscorlib]System.Object
{
    // 成员
    .field private int32 '<FID>k__BackingField'
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .field private string '<FAccount>k__BackingField'
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .field private valuetype [mscorlib]System.DateTime '<FAddtime>k__BackingField'
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .field private valuetype [mscorlib]System.Guid '<FUniqueValue>k__BackingField'
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    .field private bool '<IsAgent>k__BackingField'
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )

    // 方法
    .method public hidebysig specialname 
        instance int32 get_FID () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x205a
        // 方法起始地址(相对于文件绝对值:0x025a)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x025B: 02
        IL_0000: ldarg.0
        // 0x025C: 7B 01 00 00 04
        IL_0001: ldfld int32 Test.TAccount::'<FID>k__BackingField'
        // 0x0261: 2A
        IL_0006: ret
    } // 方法 TAccount::get_FID 结束

    .method public hidebysig specialname 
        instance void set_FID (
            int32 'value'
        ) cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x2062
        // 方法起始地址(相对于文件绝对值:0x0262)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x0263: 02
        IL_0000: ldarg.0
        // 0x0264: 03
        IL_0001: ldarg.1
        // 0x0265: 7D 01 00 00 04
        IL_0002: stfld int32 Test.TAccount::'<FID>k__BackingField'
        // 0x026A: 2A
        IL_0007: ret
    } // 方法 TAccount::set_FID 结束

    .method public hidebysig specialname 
        instance string get_FAccount () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x206b
        // 方法起始地址(相对于文件绝对值:0x026b)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x026C: 02
        IL_0000: ldarg.0
        // 0x026D: 7B 02 00 00 04
        IL_0001: ldfld string Test.TAccount::'<FAccount>k__BackingField'
        // 0x0272: 2A
        IL_0006: ret
    } // 方法 TAccount::get_FAccount 结束

    .method public hidebysig specialname 
        instance void set_FAccount (
            string 'value'
        ) cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x2073
        // 方法起始地址(相对于文件绝对值:0x0273)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x0274: 02
        IL_0000: ldarg.0
        // 0x0275: 03
        IL_0001: ldarg.1
        // 0x0276: 7D 02 00 00 04
        IL_0002: stfld string Test.TAccount::'<FAccount>k__BackingField'
        // 0x027B: 2A
        IL_0007: ret
    } // 方法 TAccount::set_FAccount 结束

    .method public hidebysig specialname 
        instance valuetype [mscorlib]System.DateTime get_FAddtime () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x207c
        // 方法起始地址(相对于文件绝对值:0x027c)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x027D: 02
        IL_0000: ldarg.0
        // 0x027E: 7B 03 00 00 04
        IL_0001: ldfld valuetype [mscorlib]System.DateTime Test.TAccount::'<FAddtime>k__BackingField'
        // 0x0283: 2A
        IL_0006: ret
    } // 方法 TAccount::get_FAddtime 结束

    .method public hidebysig specialname 
        instance void set_FAddtime (
            valuetype [mscorlib]System.DateTime 'value'
        ) cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x2084
        // 方法起始地址(相对于文件绝对值:0x0284)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x0285: 02
        IL_0000: ldarg.0
        // 0x0286: 03
        IL_0001: ldarg.1
        // 0x0287: 7D 03 00 00 04
        IL_0002: stfld valuetype [mscorlib]System.DateTime Test.TAccount::'<FAddtime>k__BackingField'
        // 0x028C: 2A
        IL_0007: ret
    } // 方法 TAccount::set_FAddtime 结束

    .method public hidebysig specialname 
        instance valuetype [mscorlib]System.Guid get_FUniqueValue () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x208d
        // 方法起始地址(相对于文件绝对值:0x028d)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x028E: 02
        IL_0000: ldarg.0
        // 0x028F: 7B 04 00 00 04
        IL_0001: ldfld valuetype [mscorlib]System.Guid Test.TAccount::'<FUniqueValue>k__BackingField'
        // 0x0294: 2A
        IL_0006: ret
    } // 方法 TAccount::get_FUniqueValue 结束

    .method public hidebysig specialname 
        instance void set_FUniqueValue (
            valuetype [mscorlib]System.Guid 'value'
        ) cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x2095
        // 方法起始地址(相对于文件绝对值:0x0295)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x0296: 02
        IL_0000: ldarg.0
        // 0x0297: 03
        IL_0001: ldarg.1
        // 0x0298: 7D 04 00 00 04
        IL_0002: stfld valuetype [mscorlib]System.Guid Test.TAccount::'<FUniqueValue>k__BackingField'
        // 0x029D: 2A
        IL_0007: ret
    } // 方法 TAccount::set_FUniqueValue 结束

    .method public hidebysig specialname 
        instance bool get_IsAgent () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x209e
        // 方法起始地址(相对于文件绝对值:0x029e)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x029F: 02
        IL_0000: ldarg.0
        // 0x02A0: 7B 05 00 00 04
        IL_0001: ldfld bool Test.TAccount::'<IsAgent>k__BackingField'
        // 0x02A5: 2A
        IL_0006: ret
    } // 方法 TAccount::get_IsAgent 结束

    .method public hidebysig specialname 
        instance void set_IsAgent (
            bool 'value'
        ) cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // 方法起始 RVA 地址 0x20a6
        // 方法起始地址(相对于文件绝对值:0x02a6)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x02A7: 02
        IL_0000: ldarg.0
        // 0x02A8: 03
        IL_0001: ldarg.1
        // 0x02A9: 7D 05 00 00 04
        IL_0002: stfld bool Test.TAccount::'<IsAgent>k__BackingField'
        // 0x02AE: 2A
        IL_0007: ret
    } // 方法 TAccount::set_IsAgent 结束

    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // 方法起始 RVA 地址 0x20af
        // 方法起始地址(相对于文件绝对值:0x02af)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02B0: 02
        IL_0000: ldarg.0
        // 0x02B1: 28 11 00 00 0A
        IL_0001: call instance void [mscorlib]System.Object::.ctor()
        // 0x02B6: 2A
        IL_0006: ret
    } // 方法 TAccount::.ctor 结束

    // 属性
    .property instance int32 FID()
    {
        .get instance int32 Test.TAccount::get_FID()
        .set instance void Test.TAccount::set_FID(int32)
    }
    .property instance string FAccount()
    {
        .get instance string Test.TAccount::get_FAccount()
        .set instance void Test.TAccount::set_FAccount(string)
    }
    .property instance valuetype [mscorlib]System.DateTime FAddtime()
    {
        .get instance valuetype [mscorlib]System.DateTime Test.TAccount::get_FAddtime()
        .set instance void Test.TAccount::set_FAddtime(valuetype [mscorlib]System.DateTime)
    }
    .property instance valuetype [mscorlib]System.Guid FUniqueValue()
    {
        .get instance valuetype [mscorlib]System.Guid Test.TAccount::get_FUniqueValue()
        .set instance void Test.TAccount::set_FUniqueValue(valuetype [mscorlib]System.Guid)
    }
    .property instance bool IsAgent()
    {
        .get instance bool Test.TAccount::get_IsAgent()
        .set instance void Test.TAccount::set_IsAgent(bool)
    }

} // 类 Test.TAccount 结束

 

 

public class TUserInfo 

.class public auto ansi beforefieldinit Test.TUserInfo
    extends [mscorlib]System.Object
{
    // 成员
    .field private int32 fid
    .field private string faccount
    .field private valuetype [mscorlib]System.DateTime faddtime
    .field private valuetype [mscorlib]System.Guid funiquevalue
    .field private bool isagent

    // 方法
    .method public hidebysig specialname 
        instance int32 get_FID () cil managed 
    {
        // 方法起始 RVA 地址 0x20b7
        // 方法起始地址(相对于文件绝对值:0x02b7)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02B8: 02
        IL_0000: ldarg.0
        // 0x02B9: 7B 06 00 00 04
        IL_0001: ldfld int32 Test.TUserInfo::fid
        // 0x02BE: 2A
        IL_0006: ret
    } // 方法 TUserInfo::get_FID 结束

    .method public hidebysig specialname 
        instance void set_FID (
            int32 'value'
        ) cil managed 
    {
        // 方法起始 RVA 地址 0x20bf
        // 方法起始地址(相对于文件绝对值:0x02bf)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x02C0: 02
        IL_0000: ldarg.0
        // 0x02C1: 03
        IL_0001: ldarg.1
        // 0x02C2: 7D 06 00 00 04
        IL_0002: stfld int32 Test.TUserInfo::fid
        // 0x02C7: 2A
        IL_0007: ret
    } // 方法 TUserInfo::set_FID 结束

    .method public hidebysig specialname 
        instance string get_FAccount () cil managed 
    {
        // 方法起始 RVA 地址 0x20c8
        // 方法起始地址(相对于文件绝对值:0x02c8)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02C9: 02
        IL_0000: ldarg.0
        // 0x02CA: 7B 07 00 00 04
        IL_0001: ldfld string Test.TUserInfo::faccount
        // 0x02CF: 2A
        IL_0006: ret
    } // 方法 TUserInfo::get_FAccount 结束

    .method public hidebysig specialname 
        instance void set_FAccount (
            string 'value'
        ) cil managed 
    {
        // 方法起始 RVA 地址 0x20d0
        // 方法起始地址(相对于文件绝对值:0x02d0)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x02D1: 02
        IL_0000: ldarg.0
        // 0x02D2: 03
        IL_0001: ldarg.1
        // 0x02D3: 7D 07 00 00 04
        IL_0002: stfld string Test.TUserInfo::faccount
        // 0x02D8: 2A
        IL_0007: ret
    } // 方法 TUserInfo::set_FAccount 结束

    .method public hidebysig specialname 
        instance valuetype [mscorlib]System.DateTime get_FAddtime () cil managed 
    {
        // 方法起始 RVA 地址 0x20d9
        // 方法起始地址(相对于文件绝对值:0x02d9)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02DA: 02
        IL_0000: ldarg.0
        // 0x02DB: 7B 08 00 00 04
        IL_0001: ldfld valuetype [mscorlib]System.DateTime Test.TUserInfo::faddtime
        // 0x02E0: 2A
        IL_0006: ret
    } // 方法 TUserInfo::get_FAddtime 结束

    .method public hidebysig specialname 
        instance void set_FAddtime (
            valuetype [mscorlib]System.DateTime 'value'
        ) cil managed 
    {
        // 方法起始 RVA 地址 0x20e1
        // 方法起始地址(相对于文件绝对值:0x02e1)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x02E2: 02
        IL_0000: ldarg.0
        // 0x02E3: 03
        IL_0001: ldarg.1
        // 0x02E4: 7D 08 00 00 04
        IL_0002: stfld valuetype [mscorlib]System.DateTime Test.TUserInfo::faddtime
        // 0x02E9: 2A
        IL_0007: ret
    } // 方法 TUserInfo::set_FAddtime 结束

    .method public hidebysig specialname 
        instance valuetype [mscorlib]System.Guid get_FUniqueValue () cil managed 
    {
        // 方法起始 RVA 地址 0x20ea
        // 方法起始地址(相对于文件绝对值:0x02ea)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02EB: 02
        IL_0000: ldarg.0
        // 0x02EC: 7B 09 00 00 04
        IL_0001: ldfld valuetype [mscorlib]System.Guid Test.TUserInfo::funiquevalue
        // 0x02F1: 2A
        IL_0006: ret
    } // 方法 TUserInfo::get_FUniqueValue 结束

    .method public hidebysig specialname 
        instance void set_FUniqueValue (
            valuetype [mscorlib]System.Guid 'value'
        ) cil managed 
    {
        // 方法起始 RVA 地址 0x20f2
        // 方法起始地址(相对于文件绝对值:0x02f2)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x02F3: 02
        IL_0000: ldarg.0
        // 0x02F4: 03
        IL_0001: ldarg.1
        // 0x02F5: 7D 09 00 00 04
        IL_0002: stfld valuetype [mscorlib]System.Guid Test.TUserInfo::funiquevalue
        // 0x02FA: 2A
        IL_0007: ret
    } // 方法 TUserInfo::set_FUniqueValue 结束

    .method public hidebysig specialname 
        instance bool get_IsAgent () cil managed 
    {
        // 方法起始 RVA 地址 0x20fb
        // 方法起始地址(相对于文件绝对值:0x02fb)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x02FC: 02
        IL_0000: ldarg.0
        // 0x02FD: 7B 0A 00 00 04
        IL_0001: ldfld bool Test.TUserInfo::isagent
        // 0x0302: 2A
        IL_0006: ret
    } // 方法 TUserInfo::get_IsAgent 结束

    .method public hidebysig specialname 
        instance void set_IsAgent (
            bool 'value'
        ) cil managed 
    {
        // 方法起始 RVA 地址 0x2103
        // 方法起始地址(相对于文件绝对值:0x0303)
        // 代码长度 8 (0x8)
        .maxstack 8

        // 0x0304: 02
        IL_0000: ldarg.0
        // 0x0305: 03
        IL_0001: ldarg.1
        // 0x0306: 7D 0A 00 00 04
        IL_0002: stfld bool Test.TUserInfo::isagent
        // 0x030B: 2A
        IL_0007: ret
    } // 方法 TUserInfo::set_IsAgent 结束

    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // 方法起始 RVA 地址 0x210c
        // 方法起始地址(相对于文件绝对值:0x030c)
        // 代码长度 7 (0x7)
        .maxstack 8

        // 0x030D: 02
        IL_0000: ldarg.0
        // 0x030E: 28 11 00 00 0A
        IL_0001: call instance void [mscorlib]System.Object::.ctor()
        // 0x0313: 2A
        IL_0006: ret
    } // 方法 TUserInfo::.ctor 结束

    // 属性
    .property instance int32 FID()
    {
        .get instance int32 Test.TUserInfo::get_FID()
        .set instance void Test.TUserInfo::set_FID(int32)
    }
    .property instance string FAccount()
    {
        .get instance string Test.TUserInfo::get_FAccount()
        .set instance void Test.TUserInfo::set_FAccount(string)
    }
    .property instance valuetype [mscorlib]System.DateTime FAddtime()
    {
        .get instance valuetype [mscorlib]System.DateTime Test.TUserInfo::get_FAddtime()
        .set instance void Test.TUserInfo::set_FAddtime(valuetype [mscorlib]System.DateTime)
    }
    .property instance valuetype [mscorlib]System.Guid FUniqueValue()
    {
        .get instance valuetype [mscorlib]System.Guid Test.TUserInfo::get_FUniqueValue()
        .set instance void Test.TUserInfo::set_FUniqueValue(valuetype [mscorlib]System.Guid)
    }
    .property instance bool IsAgent()
    {
        .get instance bool Test.TUserInfo::get_IsAgent()
        .set instance void Test.TUserInfo::set_IsAgent(bool)
    }

} // 类 Test.TUserInfo 结束

 

总结:

<FID>k__BackingField 是编译器自动生成的字段。
fid 是代码生成的字段。

在某些序列化组件中,生成的字符会是
<FID>k__BackingField。
这样会增加字符串的长度。


建议:
如果这个实体T是要序列化传输的话,还是应该自己多写些代码。

posted @ 2016-07-28 12:32  茗::流  阅读(281)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。