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

  • Thread starter Thread starter Good Enchiladas
  • Start date Start date
G

Good Enchiladas

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
 
I am not sure I understand why you would want to do this. When you are in a
method, you should not have to query the attributes of that method.
Reflection is used exterior to determine things you cannot know without
using Reflection. It is slower than explicitly coded "discovery," so I do
not see a good reason within a method to use it on itself.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Take an example of an object model using application permission attributes
on methods and/or properties. The method or property can query its own
application permission attribute to determine if the current user has the
permission necessary to invoke itself. In addition, the user interface can
query the method to determine if the user should even be presented with the
option to invoke a method or to view and/or edit a property. Buttons can be
enabled/disabled/visible/invisible. Now the attribute serves both the
method/property it describes AND users of the method/property. And this is
better than having an imperative permission check within the method/property
and the declarative permission -- defining the permissions in 2 places is
asking for trouble.

Similarly, attributes can be used on properties to define type descriptions.
Properties can use these attributes to validate themselves and the user
interface can use the same type description attributes to dynamically add
ASP.NET validation controls to an ASP.NET web page created on the fly.

I'm sure this is just the tip of the iceberg for possibilities with .NET
attributes.

Yes, I am concerned about performance. But for an ASP.NET project, careful
use of caching and/or session could solve most performance concerns with
this approach.

Hey, I'm thinking outside the box!
 
Back
Top