jeudi 12 février 2015

Explicit constructor call in C#

So, today I reflected an arbitary .NET assembly using ILSpy + dotPeek to gain deeper insight about how IL code works when I stumbled upon this weird part (dummy example):



public class SomeBaseClass {
public SomeBaseClass(SomeType[] iExpectACollection) {
...
}
}

public class SomeDerivedClass {
public SomeDerivedClass(SomeType onlyOneInstance) {
SomeType[] collection;
if(onlyOneInstance != null)
collection = new SomeType[] { onlyOneInstance };
base.\u002Ector(collection);
}
}


As far as I can see, the derived class doesn't call the base constructor in the first place, but instead does something with onlyOneInstance and then calls be base constructor.


My question is: Is it possible to call the base constructor explicitly in C# after some work has been done? Or is this only possible in IL? I know it's being easily done in e.g. Java using super(), however I've never seen it in .NET.






Aucun commentaire:

Enregistrer un commentaire