Reflection Related Quesitons

  • Thread starter Thread starter Hayato Iriumi
  • Start date Start date
H

Hayato Iriumi

(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
 
(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().Name



Mattias
 
----- Hayato Iriumi wrote: ----

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


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

new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name
System.Reflection.MethodInfo.GetCurrentMethod().Name
 
Back
Top