First of all I do not know how to explain the question properly. Therefore i explain it in more detail, maybe there is a completly different solution which i do not think of.
I search for a solution for the following problem: We went from one ORM to another. Both use different generic classes when accessing collections.
One uses List or IList
public IList<ItemTypeA> AItems{
...
}
the other one a vendor specific collection
public ACollection<ItemTypeA> AItems{
...
}
For some time we will have them in parallel until everything is tested and switched to the later.
The first idea was to use defines
#if ORMS_OLD
public IList<ItemTypeA> AItems{
...
}
#endif
#if ORMS_A
public ACollection<ItemTypeA> AItems{
...
}
#endif
Now it is a bit errorprone as it is still worked on the code to just double the code for another ORM. The inside of the properties and methods would be over 90% the same.
Another idea was to declare a base list and only change it there:
public class BaseList<T>
#if ORMS_OLD
: List<T>
#endif
#if ORMS_A
: ACollection<T>
#endif
{
}
but this looks also a bit clumsy and there was a note that you should not inherit from List because of performance reasons.
What i want to do is more a sort of defining a replacement pattern and just use the replacement pattern:
#define PLACEHOLDERLIST #if ORMS_OLD IList #else ACollection
public #PLACEHOLDERLIST<ItemTypeA> AItems{
and let some kind of preprocessor or makro-intelligence run over it.
I dont know the right word to define what i want to do. I think a sort of inline replacement or inline code generation (not a T4 generation - this is a bit clumsy to be tested ).
Is there something or exist a pattern which would be better for this use case.