469,924 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,924 developers. It's quick & easy.

Modifying value of custom attribute at runtime

I have a custom attribute with an "IsPresent" property with get; set
When the attribute is applied to a field of a class, IsPresent will be false
by default.
At runtime, I'll read in the custom attributes of every field in the class,
and would like
to set IsPresent to false if certain application conditions are met,
something like so:

static void ReadHeader( ref MusicHeaderInfo info )
FieldInfo[] fi = (FieldInfo[])info.GetType().GetFields();
for ( int i = 0; i < fi.Length; i++ )
MetadataAttribute[] attribs =
typeof(MetadataAttribute), false );
for ( int x = 0; x < attribs.Length; x++ )
Console.WriteLine( attribs[x].IsPresent ); // output is false
attribs[x].IsPresent = true; // change to true for testing
For testing:

MusicHeaderInfo info = new MusicHeaderInfo();
ReadHeader( ref info );
ReadHeader( ref info );

The output is always false. So even though I could change the value of the
attribute at runtime,
the changes didn't stick.

Any ideas?
Nov 17 '05 #1
0 1067

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Martin Lapierre | last post: by
reply views Thread by Erick Shuai | last post: by
3 posts views Thread by Michael Iantosca | last post: by
2 posts views Thread by Harry F. Harrison | last post: by
2 posts views Thread by prabhupr | last post: by
6 posts views Thread by Jeff Hegedus | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.