Explicit interface implementation

View: New views
3 Messages — Rating Filter:   Alert me  

Explicit interface implementation

by izik.shmulewitz@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,
I'm writing some code Analysis tool and I'm trying to switch to cecil
after using reflection.
My problem is that i need to know if a member is explicitly
implemented from an interface and if so what is that interface. I
noticed that I can do this by parsing but it feels wrong, is there a
better way to do so ?



thanks in advance,
Izik Shmulewitz.

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---


Re: Explicit interface implementation

by Jb Evain-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

On 9/30/09, izik.shmulewitz@... <izik.shmulewitz@...> wrote:
>  I'm writing some code Analysis tool and I'm trying to switch to cecil
>  after using reflection.
>  My problem is that i need to know if a member is explicitly
>  implemented from an interface and if so what is that interface. I
>  noticed that I can do this by parsing but it feels wrong, is there a
>  better way to do so ?

Methods that are explicitly implemented from an interface have the
method they implement in their .Overrides collection.

If the method is implicitly implemented, you don't have much choice
than descending the type hierarchy to find it yourself.

--
Jb Evain  <jb@...>

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---


Re: Explicit interface implementation

by Jonathan Pryor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Wed, 2009-09-30 at 04:44 -0700, izik.shmulewitz@... wrote:
> My problem is that i need to know if a member is explicitly
> implemented from an interface

'mdoc update' does this with:

        public static bool IsExplicitlyImplemented (MethodDefinition
        method)
        {
            return method.IsPrivate && method.IsFinal &&
        method.IsVirtual;
        }

>  and if so what is that interface.

'mdoc update' does this with:

        public static void GetInfoForExplicitlyImplementedMethod (
        MethodDefinition method, out TypeReference iface, out MethodReference ifaceMethod)
        {
        iface = null;
        ifaceMethod = null;
        if (method.Overrides.Count != 1)
        throw new InvalidOperationException ("Could not determine interface type for explicitly-implemented interface member " + method.Name);
        iface = method.Overrides [0].DeclaringType;
        ifaceMethod = method.Overrides [0];
        }

 - Jon



--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---