I like to stamp trace logs with the name of the executing Class and Method.
I can get the Class Name using GetType.Name and I can get a list of every
Method in the class using System.Reflecti on.MethodInfo objects (code
follows) But is there anyway to retrieve the name of the currently
executing Method? Or is this a lost cause?
(code sample)
Dim sClassName as String = Me.GetType.Name
Dim aMethod() as System.Reflecti on.MethodInfo =
Me.GetType.GetM ethods(BindingF lags.Public or BindingFlags.In stance or
BindingFlags.De claredOnly)
Each member of aMethod has a Name property giving me a complete list of all
of the Class Methods.
Thanks
clr 7 5565
* "clr" <crice@noaddres sinparticular> scripsit: I like to stamp trace logs with the name of the executing Class and Method. I can get the Class Name using GetType.Name and I can get a list of every Method in the class using System.Reflecti on.MethodInfo objects (code follows) But is there anyway to retrieve the name of the currently executing Method? Or is this a lost cause?
\\\
MsgBox(System.R eflection.Metho dBase.GetCurren tMethod().Name)
///
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
clr,
You can use either the StrackTrace or StackFrame classes, both in the
System.Diagnost ics namespace.
Both support skipping frames (current method), so you can encapsulate the
use of StackTrace or StackFrame in its own method, and not see the
encapsulating method.
Hope this helps
Jay
"clr" <crice@noaddres sinparticular> wrote in message
news:Ob******** ******@TK2MSFTN GP09.phx.gbl... I like to stamp trace logs with the name of the executing Class and
Method. I can get the Class Name using GetType.Name and I can get a list of every Method in the class using System.Reflecti on.MethodInfo objects (code follows) But is there anyway to retrieve the name of the currently executing Method? Or is this a lost cause?
(code sample) Dim sClassName as String = Me.GetType.Name Dim aMethod() as System.Reflecti on.MethodInfo = Me.GetType.GetM ethods(BindingF lags.Public or BindingFlags.In stance or BindingFlags.De claredOnly) Each member of aMethod has a Name property giving me a complete list of
all of the Class Methods.
Thanks clr
Hi clr, Jay,
Here's a StackTrace version:
Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnost ics.StackTrace
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name _
& " "
&CurrentStack.G etFrame(0).GetF ileLineNumber
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.Name _
& " "
&CurrentStack.G etFrame(1).GetF ileLineNumber
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function
Regards,
Fergus
Herfried, Jay, and Fergus
I situations where both the MethodBase.GetC urrentMethod and Stack Frame
example are helpful.
Your advise is appreciated.
clr
When working with the Exception Stack Trace Object is there a way to extract
the Line Number without parsing the returned string?
clr
"Fergus Cooney" <fi*****@post.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP12.phx.gbl... Hi clr, Jay,
Here's a StackTrace version:
Public Function MeAndMyCaller As String Dim CurrentStack As New System.Diagnost ics.StackTrace
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name _ & " " &CurrentStack.G etFrame(0).GetF ileLineNumber
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.Name _ & " " &CurrentStack.G etFrame(1).GetF ileLineNumber
Return "In " & Myself & vbCrLf & "Called by " & MyCaller End Function
Regards, Fergus
Hi clr,
Given that Exception StackTrace <is> a string means that you <do> have to
parse it for the line number.
Presumably you are getting this information from an Exception in the Catch
of one of the calling methods - and not where the Exception actually occurred?
Regards,
Fergus
* "clr" <crice@noaddres sinparticular> scripsit: When working with the Exception Stack Trace Object is there a way to extract the Line Number without parsing the returned string?
General information: The line number will only be available when
compiling in debug mode.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sandman |
last post by:
Ok, so I have PHP set upp to ato_prepend and auto_append files to every script
I run. So if I someone surfs to /index.php, these scripts run:
init.php -> set up DB connections and stuff. Buffers output
index.php -> The current page with it's layout, output is buffered.
postprocess.php -> Fetches buffer, applies...
|
by: vishal |
last post by:
hi
how can i get the file name from which the current executing file is
called.
i m making a scrript which will be called from many other scripts.
this script performs some calculation and then returns the result to
the script who asked for. so i want to know the script name of caller
script in the current executing script
thxs for your...
|
by: Mark Kamoski |
last post by:
Hi Everyone--
Please help.
How can one get the name of the current project and the current class?
This is the situation.
Suppose there is a project called "P1".
|
by: SLE |
last post by:
Hi there,
We have a class method which is invoked through Remoting/IIS. Within this
class method, we need to get the physical path of the assembly (dll) in
which the method is executing. we have tried:
1) System.Reflection.Assembly.GetExecutingAssembly().Location.ToString()
returns a temporary path, i.e....
|
by: Guido Kraus |
last post by:
Hi,
I wonder how to get the name of the currently executing property by using
reflection in .Net 2.0
If I use System.Reflection.MethodInfo.GetCurrentMethod().Name from within a
property I get something like "set_MyProperty" instead of "MyProperty". Is
there a way to get the current property name without the "set_" or "get_"
prefix?
| |
by: |
last post by:
Is it possible to get the name of the method that the code is currently
executing in so that I can pass it to another method? For example, in void
method1() I will call void method5(). In method5 I want to know which
method called me? Because there are many methods calling many other methods
I really want a trace of code execution from...
|
by: Chris L. |
last post by:
Hi, I'm trying to set up a generic mechanism that would allow the
following:
1: Run <this_procedure>
2: After that, run <this_review_procedure>
3: If it returns non-zero, open <this_form>
The idea is that the first procedure would have to update records.
After that, the review procedure would check if there are unupdated
records. If...
|
by: ADezii |
last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows() Method of the Recordset Object. This Method varies slightly from DAO to ADO, so for purposes of this discussion, we'll be talking about DAO Recordsets....
|
by: ADezii |
last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method (GetRows()), but only as it applies to an ADO Recordset. Although there are similarities in the 2 methodologies, the ADO Method offers 2 more Optional...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |