I have a custom attribute with an "IsPresent" property with get; set
accessors.
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 =
(MetadataAttribute[]fieldInfo[i].GetCustomAttributes(
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?
Ron