473,289 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

MethodInfo or MethodBase?

For some time, I've been adding "trace level" logging to my code using

Imports System.Reflection

Private Function XYZ( a1 as A, b1 as B, c1 as C, ...

TRACE.Log( MethodBase.GetCurrentMethod().Name _
, a1, ba, c1 )

but recently, I noticed one of my colleagues using this instead

TRACE.Log( MethodInfo.GetCurrentMethod().Name _
, a1, ba, c1 )

Is there any particular advantage to using either one?

TIA,
Phill W.
Feb 15 '06 #1
2 12197

Phill W. wrote:
For some time, I've been adding "trace level" logging to my code using

Imports System.Reflection

Private Function XYZ( a1 as A, b1 as B, c1 as C, ...

TRACE.Log( MethodBase.GetCurrentMethod().Name _
, a1, ba, c1 )

but recently, I noticed one of my colleagues using this instead

TRACE.Log( MethodInfo.GetCurrentMethod().Name _
, a1, ba, c1 )

Is there any particular advantage to using either one?


Yours is more correct - GetCurrentMethod is a Shared method of
MethodBase, not MethodInfo (which is a subclass of MethodBase).
Although both calls have exactly the same effect, it's in general a bad
idea to invoke Shared functions on subclasses of the class on which
they are actually defined. Indeed, the fact that VB.NET allows this
syntax at all is for many a _bad thing_ (C# by contrast won't let you
do this). To the uninitiated person attempting to look up
MethodInfo.GetCurrentMethod in the help, a nasty surprise awaits.

IMX the most common example you see of this is people doing
Bitmap.FromFile - FromFile is a Shared method on Image, Bitmap's
superclass. This syntax makes the reads think (naturally enough) that
Bitmap.FromFile is going to return a Bitmap - but it doesn't, it
returns an Image. Confusion ensues all round.

VB2005 fixed a similar oddity about Shared members when it made it
warnable to invoke Shared members on instance variables; it's a pity
this construct wasn't similarly dealt with.

--
Larry Lard
Replies to group please

Feb 15 '06 #2
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
TRACE.Log( MethodBase.GetCurrentMethod().Name _
, a1, ba, c1 )
or
TRACE.Log( MethodInfo.GetCurrentMethod().Name _
, a1, ba, c1 )
Yours is more correct
Thank you.
To the uninitiated person attempting to look up
MethodInfo.GetCurrentMethod in the help, a nasty surprise awaits.
Oooh ... I see what you mean ... or rather, I don't! ;-)
VB2005 fixed a similar oddity about Shared members when it made it
warnable to invoke Shared members on instance variables; it's a pity
this construct wasn't similarly dealt with.


Agreed.

Regards,
Phill W.
Feb 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AngryGerbil | last post by:
hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an ice pick into my eye! I...
2
by: Abdessamad Belangour | last post by:
Hi, I would like please to know how to get the concurrency kind of a methodInfo object. That is, which method of a methodInfo object tells that a call to a method is : "sequential", "guarded" or...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
1
by: kplkumar | last post by:
I am trying to get the method and the parameters passed to that method from the stackTrace. My code is, private void GetExecutingMethodInfo() { StackTrace trace = new StackTrace(false); ...
1
by: ian | last post by:
Hi, I can't find a solution to this, so I've brought it to the experts. Using reflection I can get a MethodInfo object pointing at an assembly's method. Where I have a MethodInfo object...
4
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Question Hello, I'm trying to get a MethodInfo class with this code: --------------------------------------------- Imports System.Reflection Public Class Form1
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
1
by: tesvit | last post by:
Hi there, I am working on a class library that should incpect a given class, make a delegate to a get Property and use it later on. Here is the code snippet: public delegate int...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.