本文整理汇总了C#中ObservableDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.ContainsKey方法的具体用法?C# ObservableDictionary.ContainsKey怎么用?C# ObservableDictionary.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.ContainsKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsObservableDictionary
public static ObservableDictionary<string, string> AsObservableDictionary(this ValidationResult result)
{
var dictionary = new ObservableDictionary<string, string>();
foreach (var item in result.ErrorList)
{
var key = item.Target.ToString();
var text = item.ErrorText;
if (dictionary.ContainsKey(key))
{
dictionary[key] = dictionary.Keys + Environment.NewLine + text;
}
else
{
dictionary[key] = text;
}
}
return dictionary;
}
示例2: cmdOnlineView_Click
private void cmdOnlineView_Click(object sender, RoutedEventArgs e)
{
try
{
var btn = sender as ToggleButton;
if (btn.IsChecked.Value)
{
_connectionDictionary = new ObservableDictionary<string, PLCConnection>();
var conns = from rw in varTabRows group rw by rw.ConnectionName;
foreach (var conn in conns)
{
if (!string.IsNullOrEmpty(conn.Key))
_connectionDictionary.Add(conn.Key, new PLCConnection(conn.Key));
}
if (!string.IsNullOrEmpty(DefaultConnection) &&
!_connectionDictionary.ContainsKey(DefaultConnection))
_connectionDictionary.Add(DefaultConnection, new PLCConnection(DefaultConnection));
lblStatus.Content = "";
foreach (var varTabRowWithConnection in varTabRows)
{
//Register Notify Changed Handler vor <connected Property
var conn = varTabRowWithConnection.Connection;
if (conn != null)
conn.Configuration.ConnectionName = conn.Configuration.ConnectionName;
}
Parallel.ForEach(_connectionDictionary, plcConnection =>
{
try
{
plcConnection.Value.AutoConnect = false;
plcConnection.Value.Connect();
}
catch (Exception ex)
{
}
});
var st = new ThreadStart(BackgroundReadingProc);
BackgroundReadingThread = new Thread(st);
BackgroundReadingThread.Name = "Background Reading Thread";
BackgroundReadingThread.Start();
ProgressBarOnlineStatus.IsIndeterminate = true;
IsOnline = true;
}
else
{
this.StopOnlineView();
}
}
catch(Exception ex)
{
lblStatus.Content = ex.Message;
}
}
示例3: ContainsKeyShouldReturnTrueForExistingKey
public void ContainsKeyShouldReturnTrueForExistingKey()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var result = observableDictionary.ContainsKey(1);
// then
result.Should().Be(true);
}
}
示例4: ContainsKeyThrowsOnNullKey
public void ContainsKeyThrowsOnNullKey()
{
// given
using (var observableDictionary = new ObservableDictionary<string, string>())
{
// when
Action retrieval = () => observableDictionary.ContainsKey((string)null);
// then
retrieval
.ShouldThrow<ArgumentNullException>()
.WithMessage("Value cannot be null.\r\nParameter name: key");
}
}
示例5: ObservableDictionaryContainsKeyTest
public void ObservableDictionaryContainsKeyTest()
{
ObservableDictionary<GenericParameterHelper, GenericParameterHelper> target = new ObservableDictionary<GenericParameterHelper, GenericParameterHelper>();
KeyValuePair<GenericParameterHelper, GenericParameterHelper> itemAdded = new KeyValuePair<GenericParameterHelper, GenericParameterHelper>(new GenericParameterHelper(1), new GenericParameterHelper(1));
KeyValuePair<GenericParameterHelper, GenericParameterHelper> itemNotAdded = new KeyValuePair<GenericParameterHelper, GenericParameterHelper>(new GenericParameterHelper(2), new GenericParameterHelper(2));
target.Add(itemAdded);
bool expectedAdded = true;
bool expectedNotAdded = false;
bool actualAdded = target.ContainsKey(new GenericParameterHelper(1));
bool actualNotAdded = target.ContainsKey(new GenericParameterHelper(2));
Assert.AreEqual(expectedAdded, actualAdded);
Assert.AreEqual(expectedNotAdded, actualNotAdded);
}