1 Answer
1

The DXA way of doing such thing is using Strongly Typed View Models and Semantic Mapping.

Using a smart combination of these two, you might not need additional logic at all.

In case you still need Schema-specific custom logic, you can test the type of the View Model (which maps to a CM Schema).

The given code fragment is too small/isolated to give an proper example of Strongly Typed View Models.

You could define View Model Types SomeSchema and SomeOtherSchema, which have a common base class. The propery LinkedComponents can then be of that base class (in general, these names are not ideal, because referring to CM Concepts; you should be using more semantic names for your View Model Types and Properties). This makes the LinkedComponent property polymorphic: the property is of a given type, but the actual linked entities will always be subclasses of that type (and you can test which subclass if needed).

Alternatively, you could define a Strongly Typed View Model which can represent the information from both Schemas and maps to both Schemas.