I have a class and it has some static methods. I have also another class inherits my first class like below;
public class Business
{
public static DataTable Get()
{
}
}
public class Model : Business
{
public int ID { get; set; }
public string CompanyName { get; set; }
}
I use it like below;
Model.Get();
Inside of Do method i try to catch type of Model class. I can catch Business class type like below inside of Do method;
public static DataTable Get()
{
Type t = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
}
But i can't catch the Model class type. How can i do that?
Note : Get method in Business class selects columns up to which class it is called from. This is why i need name of Model class. Cause name of Model class will be name of table and it will select columns from table Model.
Note 2 : Normally i use it like;
Business.Get<Model>();
and i can get all data from Model table. But i try to use it like;
Model.Get();
You can't. There is nothing called
B.Do()
. It implicitly means thatA.Do()
.Do
is a static method defined inA
. There is no metadata ofB
exist inDo
method as it's defined inA
.Being able to call
B.Do();
is just a convenience that C# compiler provides you. Note that resharper will warn you for this usage of base class member using a derived type.Do note that even if you write
Compiler converts it to
Update: As for the updated question, I recommend you to use instance methods as opposed to static methods.
Inside of get you can use
GetType().Name
to get the class name of current instance.