Conditional Compile of Generic Methods

Viewed 378

Currently working on a 2-way lookup association generic, sorted by TKey. At some point I hope to have access like the following:

public class Assoc<TKey, TValue>
{
     public TKey this[TValue value] { get; }
     public TValue this[TKey value] { get; }
}

But obviously when TKey == TValue this will fail. Out of curiosity, is there a conditional compile syntax to do this:

public class Assoc<TKey, TValue>
{
     [Condition(!(TKey is TValue))]
     public TKey this[TValue value] { get; }

     [Condition(!(TKey is TValue))]
     public TValue this[TKey value] { get; }

     public TKey Key(TValue value) { get; }

     public TValue Value(TKey value) { get; }
}
1 Answers
Related