目前正在研究按 TKey 排序的 2 路查找关联泛型。在某些时候,我希望能够访问如下:
public class Assoc<TKey, TValue>
{
public TKey this[TValue value] { get; }
public TValue this[TKey value] { get; }
}
但显然,当 TKey == TValue 时,这将失败。出于好奇,是否有条件编译语法来执行此操作:
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; }
}