Is the backing field of a compiler generated event always guaranteed to use the same name as the event?

后端 未结 3 1915
盖世英雄少女心
盖世英雄少女心 2021-01-04 22:19

C# allows us to create custom event accessors.

Action _custom;
public event Action Custom
{
    add { _custom = (Action)Delegate.Combine( _custom, value ); }         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 22:44

    The implementation of an event is a compiler implementation detail, and differs between compilers (MS c# 4 has a different implementation to MS c# < 4, and even the MS and ECMA specifications disagree).

    Personally, I'd say: if you need to access the backing field via reflection, you probably aren't using events correctly.

提交回复
热议问题