本文整理汇总了C#中System.Collections.Specialized.OrderedDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.Remove方法的具体用法?C# OrderedDictionary.Remove怎么用?C# OrderedDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.OrderedDictionary
的用法示例。
在下文中一共展示了OrderedDictionary.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CountTests
public void CountTests()
{
var d = new OrderedDictionary();
Assert.Equal(0, d.Count);
for (int i = 0; i < 1000; i++)
{
d.Add(i, i);
Assert.Equal(i + 1, d.Count);
}
for (int i = 0; i < 1000; i++)
{
d.Remove(i);
Assert.Equal(1000 - i - 1, d.Count);
}
for (int i = 0; i < 1000; i++)
{
d[(object)i] = i;
Assert.Equal(i + 1, d.Count);
}
for (int i = 0; i < 1000; i++)
{
d.RemoveAt(0);
Assert.Equal(1000 - i - 1, d.Count);
}
}
示例2: PassingEqualityComparers
public void PassingEqualityComparers()
{
var eqComp = new CaseInsensitiveEqualityComparer();
var d1 = new OrderedDictionary(eqComp);
d1.Add("foo", "bar");
Assert.Throws<ArgumentException>(() => d1.Add("FOO", "bar"));
// The equality comparer should also test for a non-existent key
d1.Remove("foofoo");
Assert.True(d1.Contains("foo"));
// Make sure we can change an existent key that passes the equality comparer
d1["FOO"] = "barbar";
Assert.Equal("barbar", d1["foo"]);
d1.Remove("FOO");
Assert.False(d1.Contains("foo"));
}
示例3: Common
private void Common (OrderedDictionary od)
{
Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
Assert.AreEqual (0, od.Count, "Count-0");
Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
od.Add ("a", "1");
Assert.AreEqual (1, od.Count, "Count-1");
od["a"] = "11";
Assert.AreEqual ("11", od["a"], "this[string]");
od[0] = "111";
Assert.AreEqual ("111", od[0], "this[int]");
DictionaryEntry[] array = new DictionaryEntry[2];
od.CopyTo (array, 1);
Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
Assert.AreEqual (1, od.Keys.Count, "Keys");
Assert.AreEqual (1, od.Values.Count, "Values");
Assert.IsTrue (od.Contains ("a"), "Contains(a)");
Assert.IsFalse (od.Contains ("111"), "Contains(111)");
od.Insert (0, "b", "2");
Assert.AreEqual (2, od.Count, "Count-2");
od.Add ("c", "3");
Assert.AreEqual (3, od.Count, "Count-3");
OrderedDictionary ro = od.AsReadOnly ();
od.RemoveAt (2);
Assert.AreEqual (2, od.Count, "Count-4");
Assert.IsFalse (od.Contains ("c"), "Contains(c)");
od.Remove ("b");
Assert.AreEqual (1, od.Count, "Count-5");
Assert.IsFalse (od.Contains ("b"), "Contains(b)");
od.Clear ();
Assert.AreEqual (0, od.Count, "Count-6");
Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
// it's a read-only reference
Assert.AreEqual (0, od.Count, "Count-7");
}
示例4: PipelineFilter
/// <devdoc>
/// Metdata filtering is the third stage of our pipeline.
/// In this stage we check to see if the given object is a
/// sited component that provides the ITypeDescriptorFilterService
/// object. If it does, we allow the TDS to filter the metadata.
/// This will use the cache, if available, to store filtered
/// metdata.
/// </devdoc>
private static ICollection PipelineFilter(int pipelineType, ICollection members, object instance, IDictionary cache)
{
IComponent component = instance as IComponent;
ITypeDescriptorFilterService componentFilter = null;
if (component != null)
{
ISite site = component.Site;
if (site != null)
{
componentFilter = site.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService;
}
}
// If we have no filter, there is nothing for us to do.
//
IList list = members as ArrayList;
if (componentFilter == null)
{
Debug.Assert(cache == null || list == null || !cache.Contains(_pipelineFilterKeys[pipelineType]), "Earlier pipeline stage should have removed our cache");
return members;
}
// Now, check our cache. The cache state is only valid
// if the data coming into us is read-only. If it is read-write,
// that means something higher in the pipeline has already changed
// it so we must recompute anyway.
//
if (cache != null && (list == null || list.IsReadOnly))
{
FilterCacheItem cacheItem = cache[_pipelineFilterKeys[pipelineType]] as FilterCacheItem;
if (cacheItem != null && cacheItem.IsValid(componentFilter)) {
return cacheItem.FilteredMembers;
}
}
// Cache either is dirty or doesn't exist. Re-filter the members.
// We need to build an IDictionary of key->value pairs and invoke
// Filter* on the filter service.
//
OrderedDictionary filterTable = new OrderedDictionary(members.Count);
bool cacheResults;
switch(pipelineType)
{
case PIPELINE_ATTRIBUTES:
foreach(Attribute attr in members)
{
filterTable[attr.TypeId] = attr;
}
cacheResults = componentFilter.FilterAttributes(component, filterTable);
break;
case PIPELINE_PROPERTIES:
case PIPELINE_EVENTS:
foreach(MemberDescriptor desc in members)
{
string descName = desc.Name;
// We must handle the case of duplicate property names
// because extender providers can provide any arbitrary
// name. Our rule for this is simple: If we find a
// duplicate name, resolve it back to the extender
// provider that offered it and append "_" + the
// provider name. If the provider has no name,
// then append the object hash code.
//
if (filterTable.Contains(descName))
{
// First, handle the new property. Because
// of the order in which we added extended
// properties earlier in the pipeline, we can be
// sure that the new property is an extender. We
// cannot be sure that the existing property
// in the table is an extender, so we will
// have to check.
//
string suffix = GetExtenderCollisionSuffix(desc);
Debug.Assert(suffix != null, "Name collision with non-extender property.");
if (suffix != null)
{
filterTable[descName + suffix] = desc;
}
// Now, handle the original property.
//
MemberDescriptor origDesc = (MemberDescriptor)filterTable[descName];
suffix = GetExtenderCollisionSuffix(origDesc);
if (suffix != null)
{
filterTable.Remove(descName);
filterTable[origDesc.Name + suffix] = origDesc;
//.........这里部分代码省略.........
示例5: RemoveAtTests
public void RemoveAtTests()
{
var d = new OrderedDictionary();
Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(0));
Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => d.RemoveAt(5));
Assert.Throws<ArgumentNullException>(() => d.Remove(null));
for (var i = 0; i < 1000; i++)
{
d.Add("foo_" + i, "bar_" + i);
}
for (var i = 0; i < 1000; i++)
{
d.RemoveAt(1000 - i - 1);
Assert.Equal(1000 - i - 1, d.Count);
}
for (var i = 0; i < 1000; i++)
{
d.Add("foo_" + i, "bar_" + i);
}
for (var i = 0; i < 1000; i++)
{
Assert.Equal("bar_" + i, d[0]);
d.RemoveAt(0);
Assert.Equal(1000 - i - 1, d.Count);
}
}
示例6: RemoveTests
public void RemoveTests()
{
var d = new OrderedDictionary();
// should work
d.Remove("asd");
Assert.Throws<ArgumentNullException>(() => d.Remove(null));
for (var i = 0; i < 1000; i++)
{
d.Add("foo_" + i, "bar_" + i);
}
for (var i = 0; i < 1000; i++)
{
Assert.True(d.Contains("foo_" + i));
d.Remove("foo_" + i);
Assert.False(d.Contains("foo_" + i));
Assert.Equal(1000 - i - 1, d.Count);
}
}
示例7: playQueueContents
private void playQueueContents(OrderedDictionary queueToPlay, Boolean isImmediateMessages)
{
long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
List<String> keysToPlay = new List<String>();
List<String> soundsProcessed = new List<String>();
lock (queueToPlay)
{
foreach (String key in queueToPlay.Keys)
{
QueuedMessage queuedMessage = (QueuedMessage)queueToPlay[key];
if (queuedMessage.dueTime <= milliseconds)
{
if ((queuedMessage.abstractEvent == null || queuedMessage.abstractEvent.isClipStillValid(key)) &&
!keysToPlay.Contains(key) && (!queuedMessage.gapFiller || playGapFillerMessage()) &&
(queuedMessage.expiryTime == 0 || queuedMessage.expiryTime > milliseconds))
{
keysToPlay.Add(key);
}
else
{
Console.WriteLine("Clip " + key + " is not valid");
soundsProcessed.Add(key);
}
}
}
if (keysToPlay.Count > 0)
{
Boolean oneOrMoreEventsEnabled = false;
if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]) && hasPearlJustBeenPlayed())
{
Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
" because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
soundsProcessed.Add(keysToPlay[0]);
}
else
{
foreach (String eventName in keysToPlay)
{
if ((eventName.StartsWith(QueuedMessage.compoundMessageIdentifier) &&
((QueuedMessage)queuedClips[eventName]).isValid) || enabledSounds.Contains(eventName))
{
oneOrMoreEventsEnabled = true;
}
}
}
if (oneOrMoreEventsEnabled)
{
openRadioChannelInternal();
soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages));
}
else
{
Console.WriteLine("All events are disabled");
}
// only close the channel if we've processed the entire queue
/*Console.WriteLine("Can we close? " + !isImmediateMessages + ", " + soundsProcessed.Count + ", " + keysToPlay.Count);
if (!isImmediateMessages && soundsProcessed.Count == keysToPlay.Count && !holdChannelOpen)
{
closeRadioInternalChannel();
}*/
Console.WriteLine("finished playing");
}
foreach (String key in soundsProcessed)
{
Console.WriteLine("Removing {0} from queue", key);
queueToPlay.Remove(key);
}
}
}
示例8: HandleCommand
private bool HandleCommand(string commandName) {
DataSourceView view = null;
if (IsDataBindingAutomatic) {
view = GetData();
if (view == null) {
throw new HttpException(SR.GetString(SR.View_DataSourceReturnedNullView, ID));
}
}
else {
return false;
}
if (!view.CanExecute(commandName)) {
return false;
}
OrderedDictionary values = new OrderedDictionary();
OrderedDictionary keys = new OrderedDictionary();
ExtractRowValues(values, true /*includeReadOnlyFields*/, false /*includePrimaryKey*/);
foreach (DictionaryEntry entry in DataKey.Values) {
keys.Add(entry.Key, entry.Value);
if (values.Contains(entry.Key)) {
values.Remove(entry.Key);
}
}
view.ExecuteCommand(commandName, keys, values, HandleCommandCallback);
return true;
}
示例9: HandleCommand
private bool HandleCommand(ListViewItem item, int itemIndex, string commandName) {
DataSourceView view = null;
if (IsDataBindingAutomatic) {
view = GetData();
if (view == null) {
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_NullView, ID));
}
}
else {
return false;
}
if (!view.CanExecute(commandName)) {
return false;
}
ListViewDataItem dataItem = item as ListViewDataItem;
if (itemIndex < 0 && dataItem == null) {
throw new InvalidOperationException(AtlasWeb.ListView_InvalidCommand);
}
OrderedDictionary values = new OrderedDictionary();
OrderedDictionary keys = new OrderedDictionary();
if (item != null) {
ExtractItemValues(values, item, false /*includePrimaryKey*/);
}
if (DataKeys.Count > itemIndex) {
foreach (DictionaryEntry entry in DataKeys[itemIndex].Values) {
keys.Add(entry.Key, entry.Value);
if (values.Contains(entry.Key)) {
values.Remove(entry.Key);
}
}
}
view.ExecuteCommand(commandName, keys, values, HandleCommandCallback);
return true;
}
示例10: PipelineFilter
private static ICollection PipelineFilter(int pipelineType, ICollection members, object instance, IDictionary cache)
{
bool flag;
IComponent component = instance as IComponent;
ITypeDescriptorFilterService filterService = null;
if (component != null)
{
ISite site = component.Site;
if (site != null)
{
filterService = site.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService;
}
}
IList list = members as ArrayList;
if (filterService == null)
{
return members;
}
if ((cache != null) && ((list == null) || list.IsReadOnly))
{
FilterCacheItem item = cache[_pipelineFilterKeys[pipelineType]] as FilterCacheItem;
if ((item != null) && item.IsValid(filterService))
{
return item.FilteredMembers;
}
}
OrderedDictionary attributes = new OrderedDictionary(members.Count);
switch (pipelineType)
{
case 0:
foreach (Attribute attribute in members)
{
attributes[attribute.TypeId] = attribute;
}
flag = filterService.FilterAttributes(component, attributes);
break;
case 1:
case 2:
foreach (MemberDescriptor descriptor in members)
{
string name = descriptor.Name;
if (attributes.Contains(name))
{
string extenderCollisionSuffix = GetExtenderCollisionSuffix(descriptor);
if (extenderCollisionSuffix != null)
{
attributes[name + extenderCollisionSuffix] = descriptor;
}
MemberDescriptor member = (MemberDescriptor) attributes[name];
extenderCollisionSuffix = GetExtenderCollisionSuffix(member);
if (extenderCollisionSuffix != null)
{
attributes.Remove(name);
attributes[member.Name + extenderCollisionSuffix] = member;
}
}
else
{
attributes[name] = descriptor;
}
}
if (pipelineType == 1)
{
flag = filterService.FilterProperties(component, attributes);
}
else
{
flag = filterService.FilterEvents(component, attributes);
}
break;
default:
flag = false;
break;
}
if ((list == null) || list.IsReadOnly)
{
list = new ArrayList(attributes.Values);
}
else
{
list.Clear();
foreach (object obj2 in attributes.Values)
{
list.Add(obj2);
}
}
if (flag && (cache != null))
{
ICollection is2;
switch (pipelineType)
{
case 0:
{
Attribute[] array = new Attribute[list.Count];
try
{
list.CopyTo(array, 0);
}
//.........这里部分代码省略.........
示例11: ReadOnly_Remove
public void ReadOnly_Remove ()
{
OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
od.Remove ("a");
}
示例12: AsReadOnly_AttemptingToModifyDictionary_Throws
public void AsReadOnly_AttemptingToModifyDictionary_Throws()
{
OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
}
示例13: playQueueContents
//.........这里部分代码省略.........
Boolean queueTooLongForMessage = queuedMessage.maxPermittedQueueLengthForMessage != 0 && willBePlayedCount > queuedMessage.maxPermittedQueueLengthForMessage;
if ((isImmediateMessages || !keepQuiet || queuedMessage.playEvenWhenSilenced) && queuedMessage.canBePlayed &&
messageIsStillValid && !keysToPlay.Contains(key) && !queueTooLongForMessage && !messageHasExpired)
{
keysToPlay.Add(key);
}
else
{
if (!messageIsStillValid)
{
Console.WriteLine("Clip " + key + " is not valid");
}
else if (messageHasExpired)
{
Console.WriteLine("Clip " + key + " has expired");
}
else if (queueTooLongForMessage)
{
List<String> keysToDisplay = new List<string>();
foreach (String keyToDisplay in queueToPlay.Keys)
{
keysToDisplay.Add(keyToDisplay);
}
Console.WriteLine("Queue is too long to play clip " + key + " max permitted items for this message = "
+ queuedMessage.maxPermittedQueueLengthForMessage + " queue: " + String.Join(", ", keysToDisplay));
}
else if (!queuedMessage.canBePlayed)
{
Console.WriteLine("Clip " + key + " has some missing sound files");
}
soundsProcessed.Add(key);
willBePlayedCount--;
}
}
}
if (keysToPlay.Count > 0)
{
if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]))
{
if (hasPearlJustBeenPlayed())
{
Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
" because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
soundsProcessed.Add(keysToPlay[0]);
}
else if (disablePearlsOfWisdom)
{
Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
" because pearls have been disabled for the last phase of the race");
soundsProcessed.Add(keysToPlay[0]);
}
}
else
{
oneOrMoreEventsEnabled = true;
}
}
}
Boolean wasInterrupted = false;
if (oneOrMoreEventsEnabled)
{
// block for immediate messages...
if (isImmediateMessages)
{
lock (queueToPlay)
{
openRadioChannelInternal();
soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
}
}
else
{
// for queued messages, allow other messages to be inserted into the queue while these are being read
openRadioChannelInternal();
soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
}
}
else
{
soundsProcessed.AddRange(keysToPlay);
}
if (soundsProcessed.Count > 0)
{
lock (queueToPlay)
{
foreach (String key in soundsProcessed)
{
if (queueToPlay.Contains(key))
{
queueToPlay.Remove(key);
}
}
}
}
if (queueHasDueMessages(queueToPlay, isImmediateMessages) && !wasInterrupted && !isImmediateMessages)
{
Console.WriteLine("There are " + queueToPlay.Count + " more events in the queue, playing them...");
playQueueContents(queueToPlay, isImmediateMessages);
}
}
示例14: playQueueContents
private void playQueueContents(OrderedDictionary queueToPlay, Boolean isImmediateMessages)
{
long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
List<String> keysToPlay = new List<String>();
List<String> soundsProcessed = new List<String>();
Boolean oneOrMoreEventsEnabled = false;
if (queueToPlay.Count > 0)
{
Console.WriteLine("Processing queue of " + queueToPlay.Count + " event(s)");
}
lock (queueToPlay)
{
foreach (String key in queueToPlay.Keys)
{
QueuedMessage queuedMessage = (QueuedMessage)queueToPlay[key];
if (isImmediateMessages || queuedMessage.dueTime <= milliseconds)
{
if ((isImmediateMessages || !keepQuiet) &&
(queuedMessage.abstractEvent == null || queuedMessage.abstractEvent.isClipStillValid(key)) &&
!keysToPlay.Contains(key) && (!queuedMessage.gapFiller || playGapFillerMessage(queueToPlay)) &&
(queuedMessage.expiryTime == 0 || queuedMessage.expiryTime > milliseconds))
{
keysToPlay.Add(key);
}
else
{
Console.WriteLine("Clip " + key + " is not valid");
soundsProcessed.Add(key);
}
}
}
if (keysToPlay.Count > 0)
{
if (keysToPlay.Count == 1 && clipIsPearlOfWisdom(keysToPlay[0]) && hasPearlJustBeenPlayed())
{
Console.WriteLine("Rejecting pearl of wisdom " + keysToPlay[0] +
" because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
soundsProcessed.Add(keysToPlay[0]);
}
else
{
foreach (String eventName in keysToPlay)
{
if ((eventName.StartsWith(QueuedMessage.compoundMessageIdentifier) &&
((QueuedMessage)queueToPlay[eventName]).isValid) || enabledSounds.Contains(eventName))
{
oneOrMoreEventsEnabled = true;
}
}
}
}
if (queueToPlay.Count > 0 && keysToPlay.Count == 0)
{
Console.WriteLine("None of the " + queueToPlay.Count + " message(s) in this queue is due or valid");
}
}
Boolean wasInterrupted = false;
if (oneOrMoreEventsEnabled)
{
// block for immediate messages...
if (isImmediateMessages)
{
lock (queueToPlay)
{
openRadioChannelInternal();
soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
}
}
else
{
// for queued messages, allow other messages to be inserted into the queue while these are being read
openRadioChannelInternal();
soundsProcessed.AddRange(playSounds(keysToPlay, isImmediateMessages, out wasInterrupted));
}
}
else
{
soundsProcessed.AddRange(keysToPlay);
}
if (soundsProcessed.Count > 0)
{
lock (queueToPlay)
{
foreach (String key in soundsProcessed)
{
if (queueToPlay.Contains(key))
{
queueToPlay.Remove(key);
}
}
}
}
if (queueHasDueMessages(queueToPlay, isImmediateMessages) && !wasInterrupted && !isImmediateMessages)
{
Console.WriteLine("There are " + queueToPlay.Count + " more events in the queue, playing them...");
playQueueContents(queueToPlay, isImmediateMessages);
}
}
示例15: HandleCommand
private bool HandleCommand(string commandName)
{
DataSourceView data = null;
if (base.IsBoundUsingDataSourceID)
{
data = this.GetData();
if (data == null)
{
throw new HttpException(System.Web.SR.GetString("View_DataSourceReturnedNullView", new object[] { this.ID }));
}
}
else
{
return false;
}
if (!data.CanExecute(commandName))
{
return false;
}
OrderedDictionary fieldValues = new OrderedDictionary();
OrderedDictionary keys = new OrderedDictionary();
this.ExtractRowValues(fieldValues, true, false);
foreach (DictionaryEntry entry in this.DataKey.Values)
{
keys.Add(entry.Key, entry.Value);
if (fieldValues.Contains(entry.Key))
{
fieldValues.Remove(entry.Key);
}
}
data.ExecuteCommand(commandName, keys, fieldValues, new DataSourceViewOperationCallback(this.HandleCommandCallback));
return true;
}