本文整理汇总了C#中System.Collections.Dictionary.SetValueForKey方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.SetValueForKey方法的具体用法?C# Dictionary.SetValueForKey怎么用?C# Dictionary.SetValueForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.SetValueForKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DictionaryForProfileItem
private static Dictionary<string, string> DictionaryForProfileItem(string key, string displayKey, string value, string displayValue)
{
Dictionary<string, string> item = new Dictionary<string, string>();
item.SetValueForKey(key, SUConstants.SUProfileItemKeyKey);
item.SetValueForKey(displayKey, SUConstants.SUProfileItemDisplayKeyKey);
item.SetValueForKey(value, SUConstants.SUProfileItemValueKey);
item.SetValueForKey(displayValue, SUConstants.SUProfileItemDisplayValueKey);
return item;
}
示例2: KNKVOKeyPathObserver
public KNKVOKeyPathObserver(Object aBaseObject, String aKeyPath, KNKVOObserver anObserver, KNKeyValueObservingOptions someOptions, Object aContext)
{
changes = new Stack<KNKVOObservationChangeTracker>();
previousObservations = new ArrayList();
baseObjectRef = new WeakReference(aBaseObject);
keyPath = aKeyPath;
context = aContext;
options = someOptions;
observer = anObserver;
//this.ObserveValueForKeyPathOfObject(aKeyPath, observedObject, null, context);
ResetObservationTree();
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionInitial) == KNKeyValueObservingOptions.KNKeyValueObservingOptionInitial) {
Dictionary<String, Object> change = new Dictionary<String, Object>();
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) == KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) {
change.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey);
}
observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, change, context);
}
}
示例3: ObserveValueForKeyPathOfObject
public void ObserveValueForKeyPathOfObject(String aKeyPath, Object anObj, Dictionary<String, Object> change, Object aContext)
{
if (change != null && change.ValueForKey(KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey) != null) {
Object oldValue = observedObject.ValueForKeyPath(keyPath);
KNKVOObservationChangeTracker tracker = new KNKVOObservationChangeTracker(oldValue, aKeyPath);
changes.Push(tracker);
// Remove our observers completely
Object currentObj = observedObject;
ArrayList keys = new ArrayList(keyPath.Split('.'));
foreach (String key in keys) {
previousObservations.Add(new KeyValuePair<Object, String>(currentObj, key));
currentObj = currentObj.ValueForKey(key);
if (currentObj == null) { break; }
}
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) == KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) {
Dictionary<String, Object> changeDict = new Dictionary<String, Object>();
changeDict.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey);
changeDict.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey);
observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);
}
} else {
ResetObservationTree();
Dictionary<String, Object> changeDict = new Dictionary<String, Object>();
if (changes.Count > 0) {
KNKVOObservationChangeTracker tracker = changes.Pop();
if (((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) && (tracker != null)) {
changeDict.SetValueForKey(tracker.OldValue, KNKVOConstants.KNKeyValueChangeOldKey);
}
}
changeDict.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey);
observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);
}
}
示例4: HandleAppcast
private void HandleAppcast(string appcast)
{
XmlNodeList xmlItems = null;
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(appcast);
xmlItems = doc.SelectNodes("/rss/channel/item");
}
catch (Exception ex)
{
ReportError(ex);
return;
}
List<SUAppcastItem> appcastItems = new List<SUAppcastItem>();
foreach (XmlNode node in xmlItems)
{
Dictionary<string, ArrayList> nodesDict = new Dictionary<string, ArrayList>();
Dictionary<string, Object> itemDescription = new Dictionary<string, object>();
// Create a dictionary of nodes for each name present,
// so we can parse by xml:lang later.
foreach (XmlNode childNode in node.ChildNodes)
{
string nodeName = childNode.Name;
ArrayList nodesForName = null;
if (!nodesDict.TryGetValue(nodeName, out nodesForName))
{
nodesForName = new ArrayList();
nodesDict.Add(nodeName, nodesForName);
}
nodesForName.Add(childNode);
}
foreach (string itemKey in nodesDict.Keys)
{
ArrayList nodes = null;
nodesDict.TryGetValue(itemKey, out nodes);
XmlNode bestNodeForKey = BestNodeInNodes(nodes);
if (bestNodeForKey.Name.Equals("enclosure"))
{
// enclosure is flattened as a separate dictionary for some reason
Dictionary<string, string> enclosureDict = new Dictionary<string, string>();
foreach (XmlAttribute attribute in bestNodeForKey.Attributes)
{
enclosureDict.SetValueForKey(attribute.InnerText, attribute.Name);
}
itemDescription.SetValueForKey(enclosureDict, "enclosure");
}
else if (bestNodeForKey.Name.Equals("pubDate"))
{
try
{
DateTime date = DateTime.Parse(bestNodeForKey.InnerText);
itemDescription.SetValueForKey(date, bestNodeForKey.Name);
}
catch
{
// Nothing
}
}
else
{
itemDescription.SetValueForKey(bestNodeForKey.InnerText.Trim(), bestNodeForKey.Name);
}
}
try
{
SUAppcastItem item = new SUAppcastItem(itemDescription);
appcastItems.Add(item);
}
catch
{
}
}
appcastItems.Sort();
appcastItems.Reverse(); // new to old
Items = appcastItems;
if (Delegate != null)
{
Delegate.AppcastDidFinishLoading(this);
}
}
示例5: fireObservation
private void fireObservation(Object newValue, Object oldValue, Boolean isPrior)
{
Dictionary<String, Object> change = new Dictionary<String, Object>();
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) == KNKeyValueObservingOptions.KNKeyValueObservingOptionNew) {
if (newValue != null) {
change.SetValueForKey(newValue, KNKVOConstants.KNKeyValueChangeNewKey);
}
}
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) {
if (oldValue != null) {
change.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey);
}
}
if (isPrior) { change.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey); }
observer.ObserveValueForKeyPathOfObject(key, observedObject, change, context);
}