[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Rick Strahl

10/28/2002 2:13:00 AM

I'm trying to figure out how to return all attributes from type, method,
property/field members by using GetCustomAttributes.

However, I never seem to get anything back from GetCustomAttributes() - the
object array is always 0 length.

I'm parsing through types something like this:


this.aXObjects = loAssembly.GetTypes();
int lnCount = this.aXObjects.Length;

for (int x=0; x< lnCount; x++)
{
Type loType = this.aXObjects[x];
...
object[] loAttributes = loType.GetCustomAttributes(true);
}


The class is defined as:

[MyAttribute("This is an example attribute")]
public class wwScripting {

...

}

with the attribute as a custom attribute class.

I get nothing returned in the call to GetCustomAttributes.

Any idea why this isn't working?


+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwthreads/
-----------------------------------
Making waves on the Web with Visual FoxPro


1 Answer

Alicia Li [MS]

10/31/2002 1:22:00 AM

0

To get attribute for assembly:
Attribute.GetCustomAttributes( Assembly )
Assembly.GetCustomAttributes(bool)

To get attributs for module:
Attribute.GetCustomAttributes( Module )
Module.GetCustomAttributes( bool)

To get attributs for type, method, property and field:
MemberInfo.GetCustomAttributes( )
Attribute.GetCustomAttributes( MemberInfo )

To get attributs for param:
ParameterInfo.GetCustomAttributes( )
Attribute.GetCustomAttributes( ParameterInfo )

Attached a little program does some of this.

Thanks
Alicia

"Rick Strahl [MVP]" <RemoveSpam_RickStrahl@hotmail.com> wrote in message
news:e93gP8hfCHA.2272@tkmsftngp10...
> I'm trying to figure out how to return all attributes from type, method,
> property/field members by using GetCustomAttributes.
>
> However, I never seem to get anything back from GetCustomAttributes() -
the
> object array is always 0 length.
>
> I'm parsing through types something like this:
>
>
> this.aXObjects = loAssembly.GetTypes();
> int lnCount = this.aXObjects.Length;
>
> for (int x=0; x< lnCount; x++)
> {
> Type loType = this.aXObjects[x];
> ...
> object[] loAttributes = loType.GetCustomAttributes(true);
> }
>
>
> The class is defined as:
>
> [MyAttribute("This is an example attribute")]
> public class wwScripting {
>
> ...
>
> }
>
> with the attribute as a custom attribute class.
>
> I get nothing returned in the call to GetCustomAttributes.
>
> Any idea why this isn't working?
>
>
> +++ Rick ---
>
> --
>
> Rick Strahl
> West Wind Technologies
> http://www.west...
> http://www.west...wwthreads/
> -----------------------------------
> Making waves on the Web with Visual FoxPro
>
>


begin 666 getattrs.cs
M=7-I;F<@4WES=&5M.PT*=7-I;F<@4WES=&5M+E)E9FQE8W1I;VX[#0IU<VEN
M9R!3>7-T96TN4G5N=&EM92Y);G1E<F]P4V5R=FEC97,[#0IU<VEN9R!3>7-T
M96TN4V5C=7)I='D[#0IU<VEN9R!3>7-T96TN4V5C=7)I='DN4&5R;6ES<VEO
M;G,[#0HO+UMA<W-E;6)L>3H@4F5F;&5C=&EO;E!E<FUI<W-I;VXH(%-E8W5R
M:71Y06-T:6]N+E)E<75E<W12969U<V4@("Q&;&%G<SU2969L96-T:6]N4&5R
M;6ES<VEO;D9L86<N365M8F5R06-C97-S(" I70T*6V%S<V5M8FQY.B!#05]!
M371R=65?24YT<G5E*")->4-!7T%-=')U95])3G1R=65A<W-E;6)L>2(I(%T-
M"EMM;V1U;&4Z($-!7T%-=')U95])3G1R=64H(DUY0T%?04UT<G5E7TE.=')U
M94UO9'5L92(I(%T-"@T*(" @(%M!='1R:6)U=&55<V%G92A!='1R:6)U=&54
M87)G971S+D%L;"P@06QL;W=-=6QT:7!L92 ]('1R=64L($EN:&5R:71E9" ]
M9F%L<V4I70T*(" @('!U8FQI8R!C;&%S<R!#05]!371R=65?24YT<G5E(#H@
M071T<FEB=71E#0H@(" @>PT*(" @(" @("!P=6)L:6,@0T%?04UT<G5E7TE.
M=')U92 H4W1R:6YG(',I#0H@(" @(" @('L-"B @(" @(" @(" @("\O0V]N
M<V]L92Y7<FET94QI;F4H(D-R96%T:6YG($%T=')I8G5T92 Z("(@*R!'9714
M>7!E*"DN5&]3=')I;F<H*2D[#0H@(" @(" @(" @("!N86UE(#T@<SL-"B @
M(" @(" @?0T*#0H@(" @(" @('!U8FQI8R!O=F5R<FED92!S=')I;F<@5&]3
M=')I;F<H*0T*(" @(" @("![#0H@(" @(" @(" @("!R971U<FX@(D-!7T%-
M=')U95])3G1R=64@5&]3=')I;F<@.B B("L@;F%M93L-"B @(" @(" @?0T*
M#0H@(" @(" @('!U8FQI8R!S=')I;F<@;F%M93L-"B @("!]#0H-"@T*<'5B
M;&EC(&-L87-S(&=E=&%T=')S#0I[#0H-"EM#05]!371R=65?24YT<G5E*")-
M>4-!7T%-=')U95])3G1R=65M971H;V0B*5T-"G!U8FQI8R!S=&%T:6,@=F]I
M9"!-86EN*"D-"GL-"@E4>7!E('0@/2!T>7!E;V8H(&=E=&%T=')S("D[#0H)
M36]D=6QE(&UD(#T@="Y-;V1U;&4[#0H)07-S96UB;'D@87-M(#T@="Y!<W-E
M;6)L>3L-"@DO+T]B:F5C="!;72!A='1R:7,@(#T@;60N1V5T0W5S=&]M071T
M<FEB=71E<RAT<G5E("D["0T*"4]B:F5C="!;72!A='1R:7,@(#T@071T<FEB
M=71E+D=E=$-U<W1O;4%T=')I8G5T97,H(&UD("D[#0H)+R]/8FIE8W0@6UT@
M871T<FES(" ]($%T=')I8G5T92Y'971#=7-T;VU!='1R:6)U=&5S*"!A<VT@
M*3L-"@E#;VYS;VQE+E=R:71E3&EN92@@871T<FES+DQE;F=T:" I.PT*"69O
M<B@@:6YT(&D],#L@:3P@871T<FES+DQE;F=T:" [:2LK("D-"@E[#0H)"4-O
M;G-O;&4N5W)I=&5,:6YE*" B071T<FEB=71E.B B("L@871T<FES6VE=+E1O
M4W1R:6YG*"D@*3L-"@E]#0H-"@T*"4UE=&AO9$EN9F\@;6EN9F\@/2!T+D=E
M=$UE=&AO9"@@(DUA:6XB+"!":6YD:6YG1FQA9W,N4W1A=&EC?$)I;F1I;F=&
M;&%G<RY0=6)L:6,@*3L-"@EA='1R:7,@/2!!='1R:6)U=&4N1V5T0W5S=&]M
M071T<FEB=71E<R@@;6EN9F\@*3L-"@EF;W(H(&EN="!I/3 [(&D\(&%T=')I
M<RY,96YG=&@@.VDK*R I#0H)>PT*"0E#;VYS;VQE+E=R:71E3&EN92@@(FUE
M=&AO9"!M86EN($%T=')I8G5T93H@(B K(&%T=')I<UMI72Y4;U-T<FEN9R@I
M("D[#0H)?0T*"0T*?0T*?0T*#0I;0T%?04UT<G5E7TE.=')U92@B37E#05]!
M371R=65?24YT<G5E5'EP92(I70T*<'5B;&EC(&-L87-S(&9O;PT*>PT*?0T*
`
end