Explicit interface implementation

44 views
Skip to first unread message

izik.sh...@gmail.com

unread,
Sep 30, 2009, 7:44:39 AM9/30/09
to mono-cecil
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.

Jb Evain

unread,
Sep 30, 2009, 7:49:37 AM9/30/09
to mono-...@googlegroups.com
Hi,

On 9/30/09, izik.sh...@gmail.com <izik.sh...@gmail.com> 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 <j...@nurv.fr>

Jonathan Pryor

unread,
Sep 30, 2009, 11:48:38 AM9/30/09
to mono-...@googlegroups.com
On Wed, 2009-09-30 at 04:44 -0700, izik.sh...@gmail.com 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


Reply all
Reply to author
Forward
0 new messages