If the code compiles you could actually compile it at runtime and use reflection to obtain the method definitions. Obtaining the method calls will be a bit trickier because you have to analyze the IL code of all methods. As far as I know there is no good support for this type of tasks build into the framework but you can use a library like Cecil to simplify the job.
Regarding using regular expressions I am not sure if they are powerful enough. Matching method definitions seams to be the easy part but even this is non trivial. I tried to give an example expression but gave up.
There are many modifiers and they are not allowed to occur in any order (while my attempt allows also invalid combinations). The modifiers are followed by the return type. This seams simple at a first look but it is not. The return type may be a generic type with arbitrarily many and arbitrarily deep nested type arguments. My attempt does not allow generics at all.
The method name will be quiet easy but my attempt is currently not correct - the name must not start with a number, you can use @ in method names and there are probably some more missing points. Then the parameter list. There may be generic types again and the modifiers ref
and out
. Finally there may be generic type constraints. And not to forget pointer types in unsafe contexts.
So I really doubt you should do it using regular expression besides you are only interested in a rough estimate or very basic cases. Because languages with matched nested brackets are not regular languages and generic type names may contain matched nested angle brackets it is not possible to identify only correct method definitions without using any extensions to regular expressions. And this was only the simple method definition - method invocation will be a lot more complex.
((public|protected|internal|private|static|abstract|sealed|extern|override|new|virtual)\s+)*[a-zA-Z0-9_]+\s+[a-zA-Z0-9_]+\s*\(.*\)