I am creating a logging control for the C # project and be able to call it by the name of the current source Wish code file, line, class, function, etc. PHP "Magic static" are uses that information but I do not see anything in the C # compiler language
I do not go looking for that thing to exist?
Using StackTrace / StackFrime Classes, you can know your control where to call it has, rather than to pass information:
private static Stringbilder list stack (out string sType) {Stringbilder SB = New stringbilder (); SType = ""; Stacktrace St = New StackTrace (true); In Furas (StackFrame f st.GetFrames ()) {MethodBase m = f.GetMethod (); If (f.GetFileName ()! = Null) {sb.AppendLine (string.Format ("{0}: {1} {2}. {3}", f.GetFileName (), f.GetFileLineNumber (), m Type disclaimer. FULName, m.Name)); If (! String.IsNullOrEmpty (m.DeclaringType.Name)) sType = m.DeclaringType.Name; }} Return sb; } (I get this code to get the call stack of the currently executed method, so it will ask for more)
Comments
Post a Comment