Replace text in code with count numbers

Due to testing and time measurement, I have to write some kind of log in an existing C # Winforms project.

I want to minimize changes to the application, so I limit my question to replacing text by counting numbers:

I want to pass the line:

Log.WriteLine(position)

many times in the code, and then replace the "position" with numbers from 1 to nin turn.

I cannot use the counter in this case due to many cycles, I am not getting the correct position.

+3
source share
3 answers

Look at that .

You can get the file name and line number instead of a counter.

static private void Trace()
{
     StackFrame callStack = new StackFrame(1, true);
     Log.WriteLine(
       String.Format("At {0}:{1}",
         callStack.GetFileName(),
         callStack.GetFileLineNumber()));
}
+2
source

, , . if, , , -

Log.WriteLine(position++)

, .

, , .

+1

, , script [insert, ].

, script .

perl-one-liner perl -e open FILE, ">", "file.cs"; $i = 0; while(<INF>) { $_ ~= s/position/$i++/g; print $_; } > mynewfile.cs

perl, , , .

+1

Source: https://habr.com/ru/post/1747944/


All Articles