Given some classes like this:
public class MyBaseClass()
{
public void MyMethodOne()
{
}
public virtual void MyVirtualMethodOne()
{
}
}
public class MyMainClass : MyBaseClass()
{
public void MyMainClassMethod()
{
}
public override void MyVirtualMethodOne()
{
}
}
If I run the following:
var myMethods= new MyMainClass().GetType().GetMethods();
I get back:
- MyMethodOne
- MyVirtualMethodOne
- MyMainClassMethod
- ToString
- Equals
- GetHashCode
- GetType
How can I avoid the last 4 methods being returned in myMethods
- ToString
- Equals
- GetHashCode
- GetType
EDIT
So far, this hack is working, but was wondering if there was a cleaner way:
var exceptonList = new[] { "ToString", "Equals", "GetHashCode", "GetType" };
var methods = myInstanceOfMyType.GetType().GetMethods()
.Select(x => x.Name)
.Except(exceptonList);
You also can do the trick: