0

Originally I have the following attribute

class CustomAttributeAttribute : Attribute { }

With usage like

[CustomAttribute]
public void Method() { ... }

Then I need to add a boolean property to the attribute:

class CustomAttributeAttribute : Attribute
{
    public MyProperty { get; set; } = false;
}

So for the further usage, the previous places where it was used, the MyProperty would be assumed false, and only seen as true when it's explicitly specified.

My question is: how do I ensure that the assemblies which already have used MyCustomAttribute would correctly work (that is, assume MyProperty == false, and also avoid other issues, whatever they are) without recompilation?

As far as I understand, the attributes content is stored serialized. So maybe I should do as described in "How to add property to DTO in a backward compatible way?" question but I have not found any explicit guidance regarding custom attributes.

Would using OptionalFieldAttribute be enough for me? Or, could it be so that it's not necessary and the simplest way would also work?

Smoke testing did not reveal any issues, also in the il dump adding the OptionalFieldAttribute did not seem to change the content of the attribute as it's stored in the using assembly. But I would still need some second opinion.

max630
  • 8,762
  • 3
  • 30
  • 55

0 Answers0