For some classes:
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'm coming back:
- Mymethodone
- MyVirtualMethodOne
- MyMainClassMethod
- Tostring
- Equally
- Gethashcode
- Gettype
How can I avoid the last 4 methods returned in myMethods
- Tostring
- Equally
- Gethashcode
- Gettype
EDIT
So far this hack is working, but it was interesting if there is a cleaner way:
var exceptonList = new[] { "ToString", "Equals", "GetHashCode", "GetType" }; var methods = myInstanceOfMyType.GetType().GetMethods() .Select(x => x.Name) .Except(exceptonList);
Alex source share