Hi Jb,
Given a C# override method, like in the following code, the C# compiler
does not emit a ".override" (MethodImpl) entry for *Derived.M* (in contrast
to explicit interface implementations).
public abstract class Base
{
public virtual void M()
{
Console.WriteLine("Base");
}
}
public class Derived : Base
{
public override void M()
{
base.M();
Console.WriteLine("Derived");
}
}
I ildasm'ed that code, added ".override Namespace.Base::M" in Derived.M and
ilasm'ed the assembly again. The C# compiler accepts this modified assembly
as a reference and *Derived.M* behaves the same way as the unmodified
version. So we see, that a compiler *could* emit ".override" for other
methods than explicit interface implementations. Also ECMA-335 (2012)
II.10.3.2 says "this directive [.override] can be used to provide an
implementation for a virtual method inherited from a base class, or a
virtual method specified in an interface implemented by this type".
KR, Ulrich
Am Freitag, 30. Mai 2014 15:50:23 UTC+2 schrieb Jb Evain:
>
> By definition, .override methods are interface methods.
>
> On Fri, May 30, 2014 at 9:51 AM, Ulrich <[email protected] <javascript:>>
> wrote:
> > Hi Jb,
> >
> > OK. And how, can I determine if the method in the Overrides collection
> is an
> > interface method without resolving the declaring type reference?
> >
> > KR, Ulrich
> >
> >
> > Am Freitag, 30. Mai 2014 09:34:55 UTC+2 schrieb Jb Evain:
> >>
> >> Hi Ulrich,
> >>
> >> This one is actually easy :)
> >>
> >> You'll see all the interface methods the method explicitly implements
> >> in the .Overrides collection of the method.
> >>
> >> Jb
> >>
> >> On Fri, May 30, 2014 at 9:22 AM, Ulrich <[email protected]> wrote:
> >> > ... without resolving a type reference.
> >> >
> >> > bool IsExplicitInterfaceImplementation(MethodDefinition method)
> >> > {
> >> > //return method.IsPrivate && method.IsFinal && method.IsVirtual;
> >> > //return method.HasOverrides;
> >> > //return method.Name.Contains(".");
> >> > }
> >> >
> >> > All these variants are heuristics and work for the current C#
> compiler,
> >> > but
> >> > may not work for other ones.
> >> > Which is the best one? Should I use a combination of heuristics? Any
> >> > alternative ideas?
> >> >
> >> > --
> >> > --
> >> > --
> >> > mono-cecil
> >> > ---
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "mono-cecil" group.
> >> > To unsubscribe from this group and stop receiving emails from it,
> send
> >> > an
> >> > email to [email protected].
> >> > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > --
> > --
> > mono-cecil
> > ---
> > You received this message because you are subscribed to the Google
> Groups
> > "mono-cecil" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/d/optout.
>
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.