I'm developing a free visual studio package (C#) which includes a feature that automatically inserts comments.
if we have the follwing code:
1 for ( x = 0; x < value; x++ )
2 {
3 if ( value1 == true &&
4 value2 == false ||
5 value3 != true)
6 {
7 return;
8 }
9 }
lets say the caret is somewhere on line number 4, and the user clicks the button to insert the comment:
//=== test comment ===
the comment should be inserted above the statement containing the caret. going backward, the statement containing the caret is the IF statement, so a new line should be inserted before the IF statement, then the comment will be inserted.
1 for ( x = 0; x < value; x++ )
2 {
3 //=== test comment ===
4 if ( value1 == true &&
5 value2 == false ||
6 value3 != true)
7 {
8 return;
9 }
10 }
The question is:
How can i find the beginning of the satement? whether it's the IF statement, FOR, RETURN, the beginning of a function definition....
this is done by the debugger when a breakpoint is set. it highlights the line representing the beginning of the statement.
Best Regards;