473,320 Members | 2,147 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,320 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 20 '05 #1
1 1339
Kelly,

try this code. It's examining any object and print the members/attributes
into the console/output window.
(It's part of an example for a German book I'm writing, so the translation
is really quick and dirty... :-(

Hope that helps, anyway

Klaus

Sub PrintObjectInfo(ByVal [Object] As Object)
'Get Type of Object to access its Members
Dim locTypeInstanz As Type = [Object].GetType

'Print Non-Custom-Attributes
Console.WriteLine("Class' Attributes:" + locTypeInstanz.FullName)
Console.WriteLine("Standard attributes:")
Console.WriteLine(" *" + locTypeInstanz.Attributes.ToString())
Console.WriteLine()

'Getting Custom-Attributes of Class
'(This way, you can only get the custom Attributes)
Console.WriteLine("Custom Attributes:")
For Each locAttribute As Attribute In
locTypeInstanz.GetCustomAttributes(True)
Console.WriteLine(" * " + locAttribute.ToString())
Next
Console.WriteLine()

'Getting members and their attributes
Dim locMembers() As MemberInfo
locMembers = locTypeInstanz.GetMembers()
Console.WriteLine("Member-Liste:")
For Each locMember As MemberInfo In locMembers
Console.WriteLine(" *" + locMember.Name + ", " _
+ locMember.MemberType.ToString)
If locMember.GetCustomAttributes(True).Length > 0 Then
Console.WriteLine(" " + New String("-"c,
locMember.Name.Length))
For Each locAttribute As Attribute In
locMember.GetCustomAttributes(False)
Console.WriteLine(" * " +
locAttribute.ToString())
For Each locPropertyInfo As PropertyInfo In
locAttribute.GetType.GetProperties
Console.Write(" " + locPropertyInfo.Name)
Console.WriteLine(": " +
locPropertyInfo.GetValue(locAttribute, Nothing).ToString)
Next
Next
End If

If locMember.MemberType = MemberTypes.Property Then
Dim locPropertyInfo As PropertyInfo = CType(locMember,
PropertyInfo)
Console.WriteLine(" Value: " +
locPropertyInfo.GetValue([Object], Nothing).ToString)
End If
Next
End Sub

"Good Enchiladas" <go************@hotmail.com> schrieb im Newsbeitrag
news:6f*****************@fe2.columbus.rr.com...
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 20 '05 #2

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...
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...
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
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.