override metadata in static constructor? override metadata in static constructor? wpf wpf

override metadata in static constructor?


Here is the link from MSDN for overridding metadata for overridding metadata for a dependency property:

It states:"Overriding metadata on a dependency property must be done prior to that property being placed in use by the property system (this equates to the time that specific instances of objects that register the property are instantiated). Calls to OverrideMetadata must be performed within the static constructors of the type that provides itself as the forType parameter of OverrideMetadata."

And the wording from the link you posted to CA1810 about when to suppress warnings:

When to Suppress Warnings

CA1810It is safe to suppress a warning from this rule if performance is not a concern; or if global state changes that are caused by static initialization are expensive or must be guaranteed to occur before a static method of the type is called or an instance of the type is created.

So, your current implementation and suppression of the warning is probably the correct route.