public static ICollection<ImplementedMember> GetExplicitlyImplementedMethods(this MethodDefinition method) { HashSet<ImplementedMember> result = new HashSet<ImplementedMember>(); if (!method.IsExplicitImplementation()) { return result; } TypeDefinition declaringType = method.DeclaringType; foreach (TypeReference interfaceRef in declaringType.Interfaces) { TypeDefinition interfaceDef = interfaceRef.Resolve(); if (interfaceDef != null) { MethodReference explicitlyImplementedMethod = method.GetExplicitlyImplementedMethodFromInterface(interfaceDef); if (explicitlyImplementedMethod != null) { ImplementedMember explicitlyImplementedMember = new ImplementedMember(interfaceRef, explicitlyImplementedMethod); if (!result.Contains(explicitlyImplementedMember)) { result.Add(explicitlyImplementedMember); } } } } return result.ToList(); }
public static ICollection<ImplementedMember> GetImplementedMethods(this MethodDefinition method) { HashSet<ImplementedMember> result = new HashSet<ImplementedMember>(); TypeDefinition declaringType = method.DeclaringType; foreach (TypeReference interfaceRef in declaringType.Interfaces) { if (interfaceRef is GenericInstanceType) { GenericInstanceType genericInstanceInterface = interfaceRef as GenericInstanceType; MethodReference implementedMethod = method.GetImplementedMethodFromGenericInstanceType(genericInstanceInterface); if (implementedMethod != null) { ImplementedMember implementedMember = new ImplementedMember(interfaceRef, implementedMethod); if (!result.Contains(implementedMember)) { result.Add(implementedMember); continue; } } } TypeDefinition interfaceDef = interfaceRef.Resolve(); if (interfaceDef != null) { MethodReference implementedMethod = method.GetImplementedMethodFromInterface(interfaceDef); if (implementedMethod != null) { ImplementedMember implementedMember = new ImplementedMember(interfaceRef, implementedMethod); if (!result.Contains(implementedMember)) { result.Add(implementedMember); } } } } return result.ToList(); }