I realize there are no macros and no such thing as __FUNCTION__ in C#,
and I know I can do this to get the current function name:
System.Reflection.MethodBase.GetCurrentMethod().Na me
But, it's rather long. Is there a way to make something like a macro
or shorthand to use this? If I make a function, it defeats the
purpose.
thx
Zytan 16 6537
Zytan wrote:
I realize there are no macros and no such thing as __FUNCTION__ in C#,
and I know I can do this to get the current function name:
System.Reflection.MethodBase.GetCurrentMethod().Na me
But, it's rather long. Is there a way to make something like a macro
or shorthand to use this? If I make a function, it defeats the
purpose.
thx
Zytan
using MB = System.Reflection.MethodBase;
namespace NS
{
public partial class CLASS
{
public void MethodToName()
{
// ...
MB.GetCurrentMethod().Name
// ...
}
}
}
I can only shorten things up to the MethodBase's name, sorry.
On 23 Feb 2007 17:26:30 -0800, "Zytan" <zy**********@yahoo.comwrote:
>I realize there are no macros and no such thing as __FUNCTION__ in C#, and I know I can do this to get the current function name:
System.Reflection.MethodBase.GetCurrentMethod().N ame
But, it's rather long. Is there a way to make something like a macro or shorthand to use this? If I make a function, it defeats the purpose.
thx
Zytan
Write a VS 2k5 macro that will type it in for you when you double click it?
Good luck with your project,
Otis Mukinfus http://www.otismukinfus.com http://www.arltex.com http://www.tomchilders.com http://www.n5ge.com
maybe you can write a Visual Studio 2005 Code Snippet if you can not find it
in http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx
--
Regards
Sheng Jiang
Microsoft MVP in Visual C++
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>I realize there are no macros and no such thing as __FUNCTION__ in C#,
and I know I can do this to get the current function name:
System.Reflection.MethodBase.GetCurrentMethod().Na me
But, it's rather long. Is there a way to make something like a macro
or shorthand to use this? If I make a function, it defeats the
purpose.
thx
Zytan
using MB = System.Reflection.MethodBase;
>
MB.GetCurrentMethod().Name
I can only shorten things up to the MethodBase's name, sorry.
Ah right, I knew about that, I should have known. Thanks, the is the
best solution I've seen so far.
Zytan
Write a VS 2k5 macro that will type it in for you when you double click it?
A possibility, yes, thanks. But, I want to be able to type it quickly
and also have it short and simple so it can be read quickly, as well.
Good luck with your project,
Thanks!
Zytan
maybe you can write a Visual Studio 2005 Code Snippet if you can not find it
inhttp://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx
You mean so that I can access the snippet and have it write all of it
out for me itself?
Again, this makes typing quick, but still it looks ugly since it's so
big.
I'd just like to be able to make macros to ease debugging. So, i can
write things to the output window quickly. I want this for
__FUNCTION__ style info, but also for other things. It looks like C#
doesn't have much for this. I could make a snippet for each one, but
wow, that's just too much when I could be typing only a few characters
for each if I had macros.
I understand why C# doesn't have macros: http://blogs.msdn.com/csharpfaq/arch.../09/86979.aspx
and it's a good thing.
But, I wish it had things to help debugging, since with macros gone,
also goes many of the debugging tools I was happy to have with C++.
Zytan
Zytan wrote:
>using MB = System.Reflection.MethodBase;
MB.GetCurrentMethod().Name
I can only shorten things up to the MethodBase's name, sorry.
Ah right, I knew about that, I should have known. Thanks, the is the
best solution I've seen so far.
I recommend that you do some performance testing if you are
to call it many times.
I would expect it to carry some overhead.
Arne
I recommend that you do some performance testing if you are
to call it many times.
I would expect it to carry some overhead.
Overhead for "using MB = System.Reflection.MethodBase;"? How is that
any different than making a fully qualified function call? Aren't
they both compiled to the same IL?
Zytan
Zytan wrote:
>I recommend that you do some performance testing if you are to call it many times.
I would expect it to carry some overhead.
Overhead for "using MB = System.Reflection.MethodBase;"? How is that
any different than making a fully qualified function call? Aren't
they both compiled to the same IL?
No - overhead of calling:
MethodBase.GetCurrentMethod()
Arne
No - overhead of calling:
>
MethodBase.GetCurrentMethod()
Oh, ok. So you were just warning me about how slow it is. I wouldn't
call that overhead, since it's not any slower than the original, and
if I need the info, and this is the only palce to get it, it must be
done.
And its just for debugging purposes anyway, so speed isn't a concern.
thanks
Zytan
Try this:
class __FUNCTION_ {
public static string _ {
get {
System.Diagnostics.StackFrame sf = new
System.Diagnostics.StackFrame(1);
return sf.GetMethod().Name;
}
}
}
Usage:
string s = __FUNCTION_._;
maybe you can write a Visual Studio 2005 Code Snippet if you can not find it
inhttp://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx
You mean so that I can access the snippet and have it write all of it
out for me itself?
Again, this makes typing quick, but still it looks ugly since it's so
big.
I'd just like to be able to make macros to ease debugging. So, i can
write things to the output window quickly. I want this for
__FUNCTION__ style info, but also for other things. It looks like C#
doesn't have much for this. I could make a snippet for each one, but
wow, that's just too much when I could be typing only a few characters
for each if I had macros.
I understand why C# doesn't have macros:http://blogs.msdn.com/csharpfaq/arch.../09/86979.aspx
and it's a good thing.
But, I wish it had things to help debugging, since with macros gone,
also goes many of the debugging tools I was happy to have with C++.
Zytan
Try this:
>
class __FUNCTION_ {
public static string _ {
get {
System.Diagnostics.StackFrame sf = new
System.Diagnostics.StackFrame(1);
return sf.GetMethod().Name;
}
}
}
Usage:
string s = __FUNCTION_._;
Damn, again the post didn't go through, i'll ty again:
Thanks Tim. I wonder if it can be extended for __FILE__ and __LINE__.
Also, I would love to have something report the fully qualified method
name! Possible?
Zytan
Zytan wrote:
>Try this:
class __FUNCTION_ { public static string _ { get { System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1); return sf.GetMethod().Name; } } }
Usage: string s = __FUNCTION_._;
Damn, again the post didn't go through, i'll ty again:
Thanks Tim. I wonder if it can be extended for __FILE__ and __LINE__.
Also, I would love to have something report the fully qualified method
name! Possible?
http://msdn2.microsoft.com/en-us/lib...e_members.aspx
Arne http://msdn2.microsoft.com/en-us/lib...tics.stackfram...
Thanks.
So, I could step up the stack frame and find out exactly what called
what to get here? I find the c# reference on MSDN rather confusing.
It shows so little information, and then attempts to explain things
with code, and shows a ton of code. It's overwhelming.
Actually, what I meant by 'fully qualified' is the class hierarchy.
Zytan
Zytan wrote:
>http://msdn2.microsoft.com/en-us/lib...tics.stackfram...
So, I could step up the stack frame and find out exactly what called
what to get here?
Yes. Note that line numbers are not always available.
Actually, what I meant by 'fully qualified' is the class hierarchy.
That is something completely different, but you should also
be able to retrieve that via reflection.
Type BaseType property can be used for that.
Arne
> http://msdn2.microsoft.com/en-us/lib...tics.stackfram...
So, I could step up the stack frame and find out exactly what called
what to get here?
Yes. Note that line numbers are not always available.
Actually, what I meant by 'fully qualified' is the class hierarchy.
That is something completely different, but you should also
be able to retrieve that via reflection.
Type BaseType property can be used for that.
Arne
Ok, i'll take a look. I find the MSDN docs quite unhelpful in showing
how methods can be used, but i'll dig around some. Thanks Arne
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: foo |
last post by:
I'm creating a debug class called debug_mem_allocation for the purpose
of finding memory leaks.
I used macro's to replace the new and delete operators.
My problem is with trying to replace the...
|
by: TheDD |
last post by:
Hello all,
right now, i'm using the following macro to automatically add informations
to exceptions:
#define THROW(Class, args...) throw Class(__FILE__, __LINE__, ## args)
but AFAIK, it's...
|
by: Johannes Zellner |
last post by:
Hello,
Is it possible to have a preprocessor macro, which prints information
like the function name of the current context like
void SomeClass:some_member()
{
NIFTY_MACRO();
...
|
by: Mockey Chen |
last post by:
I using #define as following:
#include <stdio.h>
#define LOG_PREFIX "Current function: <" __FUNCTION__ ">: "
int main()
{
printf(LOG_PREFIX "some thing.\n");
return 0;
}
|
by: Bilgehan.Balban |
last post by:
Hi,
I'm trying to convert this:
printf("format str %s, %s", "str arg 1", "str arg 2 etc.");
to this:
printf("%s: " "format str %s, %s", __FUNCTION__, "str arg 1", "str arg2
etc.");
|
by: derelict |
last post by:
Hey all, im getting desperate now.
I have a macro running in Word 2003, when I run the macro it *should* put a 'bottom' cell border in each cell that has the style used - this included a border at...
|
by: Neo |
last post by:
Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I...
|
by: somenath |
last post by:
Hi ALL ,
I need to print the name of the function as my debug message. I have
tried the following way
#include<stdio.h>
#include<stdlib.h>
#define __STR(x) _VAL(x)
#define _VAL(x) #x
int...
|
by: Peng Yu |
last post by:
Hi,
__PRETTY_FUNCTION__ is a macro that gives function name, etc. I'm
wondering if there is a macro to get the class name inside a member
function.
Thanks,
Peng
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |