Iterator blocks and inheritance

前端 未结 4 1989
心在旅途
心在旅途 2021-02-13 01:58

Given a base class with the following interface:

public class Base
{
    public virtual IEnumerable GetListOfStuff()
    {
        yield return \"F         


        
4条回答
  •  别那么骄傲
    2021-02-13 02:38

    Incidentally, the reason for this odd behaviour is that the CLR security team changed the verifier right before v2 shipped, such that it became unverifiable to do a non-virtual call on a virtual method of one class from a method in a different class.

    For further explanation of this issue see my article on the subject from a few years back.

    http://blogs.msdn.com/ericlippert/archive/2005/11/14/why-are-base-class-calls-from-anonymous-delegates-nonverifiable.aspx

    This is now out-of-date; we've fixed up the compiler so that it now generates the helper for you.

提交回复
热议问题