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; }
}
No, there is no conditional compiltation based on Generic types.
Generics substitutions are performed at runtime, not compile time.
This is one of the differences between .NET generics and C++ templates.
Generics also don't have the concept of specialization that C++ templates have.
http://msdn.microsoft.com/en-us/library/c6cyy67b.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With