I am using C# as a scripting language i my app with CS-Script as the compiler interface. When a script causes a runtime error, the exception stacktrace contains information on the namespace, class and methodname of the method causing the exception.
I have the source code in a string which contains many methods in different namespaces and classes.
Detecting a runtime error, i have parsed out namespace, class and method name where the error occured. Now i need to find the character index in the source string where the failing method is declared. Having that index, i can find the line number and can then tell the user where the error occurred.
Lets say the code looks like this:
namespace MyNamespace {
public static class MyClass {
public static int OtherMethod(int val) {
return val * 2;
}
public static int MyMethod(int val) {
return 10 / val;
}
}
}
What is known is that the namespace is MyNamespace, that the class is MyClass and that the method name we are looking for is MyMethod.
What i need to find out is that the identifier MyMethod within this namespace and class is declared at line y in the code.
I have tried to make a C# Regex expression, but i can't make it work and now these Regex hieroglyphs are beginning to give me a bad headache. What i came up with is this:
".*namespace\s+MyNamespace.*class\s+MyClass.*MyMethod\s*\("
How do I do this?