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

Reflection Related Quesitons

(1) Can custom attribute be assigned to a class (or other elements) at
runtime? I tried to use MethodInfo to do that, but it doesn't seem to be
possible...

(2) Can I get the name of the method that is currently running? The example
follows...

Sub MyMethod()
Dim strMethodName As String = System.Reflection.Assembly.blahblah...
Console.WriteLine("The name of the method that is currently runnning is
{0}",strMethodName)
End Sub

TIA
Nov 20 '05 #1
4 868
(1) Can custom attribute be assigned to a class (or other elements) at
runtime? I tried to use MethodInfo to do that, but it doesn't seem to be
possible...
Only to types dynamicly created with Reflection Emit, not existing
compiled code.

(2) Can I get the name of the method that is currently running?


System.Reflection.MethodBase.GetCurrentMethod().Na me

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2

----- Hayato Iriumi wrote: ----
(1) Can custom attribute be assigned to a class (or other elements) a
runtime? I tried to use MethodInfo to do that, but it doesn't seem to b
possible..
I'm not really sure I understand what you'd do this for. Could you give a hint as to what you're trying to accomplish here

(2) Can I get the name of the method that is currently running


Either of these will get you the name of the currently executing method

new System.Diagnostics.StackTrace().GetFrame(0).GetMet hod().Name
System.Reflection.MethodInfo.GetCurrentMethod().Na me

Nov 20 '05 #3
Say, the values I want to asssign to the attribute are stored in
database...

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Interesting. Thank you very much for sharing your knowledge!

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

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

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
2
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
2
by: Jason | last post by:
Hello, I"m trying to invoke a method using reflection on a DLL that is already within a project. However, I"m having a few problems and didn't know if anyone has any bright ideas. Please note,...
6
by: Andrew Robinson | last post by:
assuming that I have a class public class MyClass { public string FirstName { get {...} set {...} } } how can I assign the FirstName property using reflection on a generic class
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
3
by: puzzlecracker | last post by:
1. Can an abstract class have some implementation (say default assuming derived chooses not to implement it)? 2. Does CSharp has a concept of inner class comparable to java's, where inner class...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
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
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
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
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...
0
tracyyun
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 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.