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>
'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