Search code examples
c#immutabilityfxcoppropertyinfofieldinfo

C# - Are FieldInfo and PropertyInfo Immutable or Mutable?


Basically, I have the following:

protected static readonly FieldInfo SpecialField = FindSpecialField();

FxCop is complaining to me though that I should not make a field readonly if it is mutable because the members can be changed. Are FieldInfo and PropertyInfo immutable or mutable. Basically, can I suppress this message?


Solution

  • FieldInfo itself looks immutable, but derviations of it may or may not be. For example, the FieldBuilder can be modified. Same holds for PropertyInfo.

    So, if you know it's always a FieldInfo obtained from reflection, then chances are you will be safe.