Monday 15 June 2015

c# - How do I get the current line number? -



c# - How do I get the current line number? -

here illustration of want do:

messagebox.show("error line number "+currentlinenumber);

current line number line number in source code of piece of code.

how can that?

in .net 4.5 / c# 5, can compiler work you, writing utility method uses new caller attributes:

static void somemethodsomewhere() { showmessage("boo"); } ... static void showmessage(string message, [callerlinenumber] int linenumber = 0, [callermembername] string caller = null) { messagebox.show(message + " @ line " + linenumber + " (" + caller + ")"); }

this display, example:

boo @ line 39 (somemethodsomewhere)

there's [callerfilepath] tells path of original code file.

c# wpf c#-4.0 line-numbers

No comments:

Post a Comment