static MyStringId() { m_idByString = new Dictionary <string, MyStringId>(50); m_stringById = new Dictionary <MyStringId, string>(50, Comparer); NullOrEmpty = GetOrCompute(""); Debug.Assert(NullOrEmpty == default(MyStringId)); Debug.Assert(NullOrEmpty.m_id == MyLibraryUtils.GetHash(null)); Debug.Assert(NullOrEmpty.m_id == MyLibraryUtils.GetHash("")); }
public static MyStringId GetOrCompute(string str) { MyStringId result; if (str == null) { result = NullOrEmpty; } else if (!m_idByString.TryGetValue(str, out result)) { result = new MyStringId(MyLibraryUtils.GetHash(str)); m_stringById.Add(result, str); m_idByString.Add(str, result); } return(result); }