Let’s say I have,
public class A
{
public static void MyAMethod()
{
}
public class B
{
}
}
public class C : A.B
{
public void MyCMethod()
{
MyAMethod();// I need to call this
}
}
Now I need to call MyAMethod from class C.
Edit: In my situation class A is unavailable. So, I cannot use A.MyAMethod.
If you take a look at the IL code for
you will find that
MyBMethodis implemented(?) asAs you can see the call to NestedTest.A::MyAMethod() is hard-coded i.e. the “magic” was already done by the C#->IL compiler. (*)
You could get the information you need to call the static method via reflection, e.g. (without error handling and rather crude)
but there is probably a better solution for your specific problem.
(*) and the c# compiler does that only as specified in http://msdn.microsoft.com/en-us/library/ms228593.aspx
The scope of a name is the region of program text within which it is possible to refer to the entity declared by the name without qualification of the name […]
– The scope of a member declared by a class-member-declaration (§10.1.6) is the class-body in which the declaration occurs. In addition, the scope of a class member extends to the class-body of those derived classes that are included in the accessibility domain (§3.5.2) of the member.
class Bis part of the class-body of class A,class Cis not. Andclass Cis also not derived from class A.