I have a class that has a number of properties, one of which is to be an object, let's call it ExtraData. This can be an object of any one of three different types, with no shared fields between all three.
Should I create a Marker Interface that all three object classes implement and make the ExtraData property be of that Interface type? Everything I have read says to avoid this in .NET and use Custom Attributes whenever possible. If I do this, would I make ExtraData a simple Object and check the attributes to determine it's type? This seems like a lot of extra work if I want to use this data, checking attributes and casting accordingly.
Is this an exception to the "Don't use Marker Interfaces" rule? Or am I missing something obvious?
Thanks.
It's not really clear what your intention is. To answer your actual question, using an interface like that is perfectly acceptable and, disregarding the wisdom of the approach, if you need to restrict the value of the property to a handful of types, that seems like a legitimate approach.
In reality, though, there could be better approaches, but without more information about what you're doing I can't suggest anything.