473,387 Members | 1,501 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,387 software developers and data experts.

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 3682
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
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.