c# - Get function name from text file base on line of code -
i got c++ source called 'mycpp.cpp', locates in: c:\mycpp.cpp
... 5 string cpluspluswarningfunction() 6 { 7 int = 69; 8 int b = + 1; 9 = b; 10 b = 69; 11 return "42 answer"; 12 } ...
now want write c# function this
void codeanalyzer() { string path = @"c:\mycpp.cpp"; int line = 11; ienumerable<string> loc = file.readlines(path); string code = loc.elementat(line-1);//yes, 'return "42 answer";', job! string functionfullname = "???";//this suppose string 'cpluspluswarningfunction()', how it??? messagebox.show(string.format("the code {0} @ line {1} in function {2}",code,line,functionfullname)); }
how can function name replace string "???" in c# code above?
i know can done because ms' fxcop can it, sort of (fxcop analyzes compiled object code, not original source code). if compiled object code can done, why not original source code.
and visual studio can image below, hope there way access visual studio api:
thank reading.
given there 1 function, each line try
//do in foreach loop iterate through every line string functionname; if (line.split(' ').where(x => x.contains("()") && !x.contains(".")).count() > 0) { functionname = line.split(' ').where(x => x.contains("()") && !x.contains(".")).first(); }
now work on example code, very rudimentary , i'm sure there lot of cases wouldn't work. might not bad starting point though.
Comments
Post a Comment