public interface IInterface
{
void Foo();
}
internal class Interface : IInterface
{
private readonly object m_Obj;
public Interface(object obj)
{
m_Obj = obj;
}
public void Foo()
{
throw new NotImplementedException();
}
}
class Program
{
static void Main(string[] args)
{
var interfaces = GetInterfaces();
}
private static IEnumerable<IInterface> GetInterfaces()
{
yield return new Interface(Resolve());
}
private static object Resolve()
{
return new object();
}
}
Worum es mir geht ist der Methoden Call von Resolve() innerhalb des yield return. Der IL Code sieht so aus:
.method private hidebysig static class [mscorlib]System.Collections.Generic.IEnumerable`1<class OpCode.IInterface>
GetInterfaces() cil managed
{
// Code size 14 (0xe)
.maxstack 1
.locals init ([0] class OpCode.Program/'<GetInterfaces>d__0' V_0,
[1] class [mscorlib]System.Collections.Generic.IEnumerable`1<class OpCode.IInterface> V_1)
IL_0000: ldc.i4.s -2
IL_0002: newobj instance void OpCode.Program/'<GetInterfaces>d__0'::.ctor(int32)
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: stloc.1
IL_000a: br.s IL_000c
IL_000c: ldloc.1
IL_000d: ret
} // end of method Program::GetInterfaces
Im FxCop hab ich schon mehreres Versucht. Es wird für die Rückgabe ein Compile Generiertes Object zurück gegeben. Soweit so klar. Aber ich komme einfach nicht an den MethodCall vom Resolve() ran.
...
Visit(method.Body);
foreach (InstanceInitializer instanceInitializer in method.Instructions().Select(t => t.Value).OfType<InstanceInitializer>())
{
Visit(instanceInitializer.Body);
}
...
Weiß einer wie ich wirklich an ALLE Methodenaufrufe heran komme? Gleiches Problem wird sicherlich auch bei Lamda's auftauchen.