473,503 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection: Determining a Method's Attributes from within the Method

Is it possible to determine a method's own attributes from within the method
without hardcoding the name of the method as a constant within the method?
Please tell me if it is possible and how it is done.

Thank you,
Kelly
Nov 17 '05 #1
3 3688
Good Enchiladas wrote:
Is it possible to determine a method's own attributes from within the
method without hardcoding the name of the method as a constant within
the method? Please tell me if it is possible and how it is done.


Presumably you're talking about .NET development, since native C++ has no
reflection abilities.

In .NET development, you can use the System::Environment::StackTrace
property to get a stack trace of the current execution context as a string,
and then parse the full class name, method name and parameters from that
string.

If there's a more direct way, I don't know it - but I wouldn't be surprised
if there is!

-cd
Nov 17 '05 #2
Hi Carl,
Presumably you're talking about .NET development, since native C++ has no
reflection abilities.

In .NET development, you can use the System::Environment::StackTrace
property to get a stack trace of the current execution context as a string, and then parse the full class name, method name and parameters from that
string.

If there's a more direct way, I don't know it - but I wouldn't be surprised if there is!


Actually, there is :)

Just use the GetCurrentMethod() static method of the
System::Reflection::MethodBase class.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #3
Tomas Restrepo (MVP) wrote:
Hi Carl,
Presumably you're talking about .NET development, since native C++
has no reflection abilities.

In .NET development, you can use the System::Environment::StackTrace
property to get a stack trace of the current execution context as a
string, and then parse the full class name, method name and
parameters from that string.

If there's a more direct way, I don't know it - but I wouldn't be
surprised if there is!


Actually, there is :)

Just use the GetCurrentMethod() static method of the
System::Reflection::MethodBase class.


I *knew* it was there somewhere! Just couldn't find it in the mass of .NET
classes.

-cd
Nov 17 '05 #4

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

Similar topics

8
2520
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
0
2160
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using...
0
1457
by: James Cohen | last post by:
Hi, I hope somebody can help me out, Im looking for a way to retreive the original filename & line number of a Reflection.MemberInfo instance. Ill provide some background on what it is that im...
5
2292
by: Wiktor Zychla | last post by:
Hello, I still have some problems with custom attributes and I ask someone for a helpful hand. In the appendix is the trivial ILAsm code with single custom attribute. The code compiles OK but...
1
2365
by: Pieter Breed | last post by:
Hi All, I am trying to use the attribute/reflection system to as much potential as I can think of, but I've run into a snag. I would appreciate it if someone would point me in the right...
1
1897
by: Rich Noons | last post by:
Hi, I'm trying to recognise whether a function is deprecated or not when reflecting a method. eg. or
1
1346
by: Good Enchiladas | last post by:
Is it possible to determine a method's own attributes from within the method without hardcoding the name of the method as a constant within the method? Please tell me if it is possible and how it...
15
2118
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
4
6804
by: =?Utf-8?B?QWJoaQ==?= | last post by:
I am using Reflection to invoke methods dynamically. I have got a special requirement where I need to pass a value to method by setting the custom method attribute. As I cannot change the...
17
2291
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
0
7202
marktang
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,...
0
7086
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...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
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...
1
6991
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...
0
3167
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...
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
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...

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.