謝謝大家對他們的意見和幫助
下面是我想出了最後的工作液用。它與其他類似的收藏集成在一起。我最初使用了一個列表,但我需要一個字符串作爲其他收藏的鑰匙
// ************************** Ordered Dictionary - works ****************
// http://stackoverflow.com/questions/2722767/c-sharp-order-preserving-data-structures
// http://www.go4expert.com/articles/understanding-c-sharp-dictionaries-t30034/
public OrderedDictionary m_oCol;
public OrderedDictionary m_oColReverse;
public clsFeatureCollection()
: base()
{
m_oCol = new OrderedDictionary();
m_oColReverse = new OrderedDictionary();
}
public IEnumerator GetEnumerator()
{
return m_oCol.GetEnumerator();
}
public void Add(IFeature pFeature, string strBefore = "", string strAfter = "", bool bReverse = false)
{
if (bReverse == true)
{
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim());
}
if (!ContainsItem(pFeature.OID.ToString()))
{
m_oCol.Add(pFeature.OID.ToString(), new clsFeature(pFeature.OID, pFeature.ShapeCopy));
}
}
public void AddBefore(IFeature pFeature, string strBefore, bool bReverse = false)
{
if (bReverse == true)
{
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim());
}
if (!ContainsItem(pFeature.OID.ToString()))
{
if (strBefore != null)
{
int index = GetIndex(m_oCol, strBefore);
if (index > 0)
{
m_oCol.Insert(index - 1, pFeature.OID.ToString(), new clsFeature(pFeature.OID, pFeature.ShapeCopy));
}
else
{
m_oCol.Insert(0, pFeature.OID.ToString(), new clsFeature(pFeature.OID, pFeature.ShapeCopy));
}
}
}
}
public void AddAfter(IFeature pFeature, string strAfter, bool bReverse = false)
{
if (bReverse == true)
{
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim());
}
if (!ContainsItem(pFeature.OID.ToString()))
{
if (!string.IsNullOrEmpty(strAfter))
{
int index = GetIndex(m_oCol, strAfter);
m_oCol.Insert(index + 1, pFeature.OID.ToString(), new clsFeature(pFeature.OID, pFeature.ShapeCopy));
}
else
{
m_oCol.Insert(0, pFeature.OID.ToString(), new clsFeature(pFeature.OID, pFeature.ShapeCopy));
}
}
}
public int Count
{
get { return m_oCol.Count; }
}
public void Remove(int Id)
{
m_oCol.RemoveAt(Id);
}
public clsFeature Item(int Position)
{
try
{
clsFeature value = (clsFeature)m_oCol.Cast<DictionaryEntry>().ElementAt(Position).Value;
return value;
}
catch (Exception)
{
throw;
}
}
public void Clear()
{
m_oCol = new OrderedDictionary();
m_oColReverse = new OrderedDictionary();
}
public bool Reverse(string valueRenamed)
{
bool bReverse = false;
try
{
if (m_oColReverse.Contains(valueRenamed))
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
if (ex is ArgumentException | ex is IndexOutOfRangeException)
{
bReverse = false;
}
}
return bReverse;
}
public bool ContainsItem(string oidValue)
{
bool bContainsItem = false;
string intOID = oidValue.ToString();
try
{
// dictionary
if (m_oCol.Contains(intOID))
{
bContainsItem = true;
}
else
{
bContainsItem = false;
}
return bContainsItem;
}
catch (Exception ex)
{
if (ex is ArgumentException | ex is IndexOutOfRangeException)
{
bContainsItem = false;
}
}
return bContainsItem;
}
public static int GetIndex(OrderedDictionary dictionary, string key)
{
for (int index = 0; index < dictionary.Count; index++)
{
if (dictionary[index] == dictionary[key])
{
return index;
}
}
return -1;
}
// ****************************** End Ordered Dictionary - works ************************
UAC將破壞您的計劃,您無法在沒有提升的情況下向HKLM寫信。除非你編寫了一個改變密鑰可訪問性的安裝程序。許可證實施代碼是您購買的代碼種類。花一分錢賺一分錢。 –
你應該使用boxedapp。它必須幫助你。 –