/// <summary> /// 获取 /// </summary> /// <param name="keyA"></param> /// <returns></returns> public Dictionary <TKeyB, TValue> Get(TKeyA keyA) { if (DataA.ContainsKey(keyA)) { return(DataA[keyA]); } return(new Dictionary <TKeyB, TValue>()); }
/// <summary> /// 添加,如果已有则覆盖。 /// </summary> /// <param name="keyA"></param> /// <param name="keyB"></param> /// <param name="val"></param> public void Add(TKeyA keyA, TKeyB keyB, TValue val) { if (!DataA.ContainsKey(keyA)) { DataA[keyA] = new Dictionary <TKeyB, TValue>(); } if (!DataB.ContainsKey(keyB)) { DataB[keyB] = new Dictionary <TKeyA, TValue>(); } DataA[keyA][keyB] = val; DataB[keyB][keyA] = val; }
/// <summary> /// 是否包含键值A,且A集合中也包含B /// </summary> /// <param name="keyA"></param> /// <param name="keyB"></param> /// <returns></returns> public bool ContainsKeyAB(TKeyA keyA, TKeyB keyB) { return(DataA.ContainsKey(keyA) && DataA[keyA].ContainsKey(keyB)); }