IntroSpection 
Author Message
 IntroSpection

Hi All,

I have a strange "bug"
I am introspecting a class to get a list of methods and a list of attributes
applied to those methods.
When I use the following code to retrieve a list of attributes they always
come back in the order in which I put them in the code editor, except the
3rd method.
The 3rd method always returns its attribute list in reverse.
Any Ideas?

Paul
------------------------

----class to be introspected----
[WebMethod]
[SecurityAttribute("Developer")]
[PrincipalPermission(SecurityAction.Demand, Role="Developer")]
public string myDevonlyMethod()
{
return "You have Dev Roles";

Quote:
}

[WebMethod]
[SecurityAttribute("ProjectMgr,User,Developer")]
[PrincipalPermission(SecurityAction.Demand, Role="ProjectMgr")]
public string myDev_User_PrjMgr_Method()
{
return "You have All Roles";
Quote:
}

[WebMethod]
[SecurityAttribute("User")]
[PrincipalPermission(SecurityAction.Demand, Role="User")]
public string myUserOnlyMethod()
{
return "You have User Roles";
Quote:
}

[WebMethod]
[SecurityAttribute("ProjectMgr")]
[PrincipalPermission(SecurityAction.Demand, Role="ProjectMgr")]
public string myprjOnlyMethod()
{
return "You have Prj Mgr Roles";
Quote:
}

----code to introspect-------

MemberInfo info = t.GetMethod(Method);
object[] attributes = info.GetCustomAttributes(true);



Sun, 21 Nov 2004 20:22:59 GMT  
 IntroSpection
Paul,

    Your code shouldn't care about the order that the attributes are
returned to you (what is the point really?).  If you have a custom attribute
that can be applied multiple times, and are concerned with the order of that
attribute, then I would create a field on the attribute with an index value
that a group of them can be ordered on.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hi All,

> I have a strange "bug"
> I am introspecting a class to get a list of methods and a list of
attributes
> applied to those methods.
> When I use the following code to retrieve a list of attributes they always
> come back in the order in which I put them in the code editor, except the
> 3rd method.
> The 3rd method always returns its attribute list in reverse.
> Any Ideas?

> Paul
> ------------------------

> ----class to be introspected----
> [WebMethod]
> [SecurityAttribute("Developer")]
> [PrincipalPermission(SecurityAction.Demand, Role="Developer")]
> public string myDevonlyMethod()
> {
> return "You have Dev Roles";
> }
> [WebMethod]
> [SecurityAttribute("ProjectMgr,User,Developer")]
> [PrincipalPermission(SecurityAction.Demand, Role="ProjectMgr")]
> public string myDev_User_PrjMgr_Method()
> {
> return "You have All Roles";
> }
> [WebMethod]
> [SecurityAttribute("User")]
> [PrincipalPermission(SecurityAction.Demand, Role="User")]
> public string myUserOnlyMethod()
> {
> return "You have User Roles";
> }
> [WebMethod]
> [SecurityAttribute("ProjectMgr")]
> [PrincipalPermission(SecurityAction.Demand, Role="ProjectMgr")]
> public string myprjOnlyMethod()
> {
> return "You have Prj Mgr Roles";
> }
> ----code to introspect-------

> MemberInfo info = t.GetMethod(Method);
> object[] attributes = info.GetCustomAttributes(true);



Sun, 21 Nov 2004 20:44:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. introspection equivalent in C/C++?

2. introspection: How self aware is a pointer?

3. Reflection / Introspection

 

 
Powered by phpBB® Forum Software