Castle.MonoRail.Framework.Flash.Sweep C# (CSharp) Method

Sweep() public method

Remove any element thats not marked to be kept. This method is automatically called by the framework after the controller is processed.
public Sweep ( ) : void
return void
		public void Sweep()
		{
			if (hasSwept)
			{
				object[] keys = new object[Keys.Count];

				Keys.CopyTo(keys, 0);

				if (keys.Length != 0)
				{
					keep.AddRange(keys);
				}
			}

			if (keep.Count == 0)
			{
				Clear();
			}
			else
			{
				object[] keys = new object[Keys.Count];

				Keys.CopyTo(keys, 0);

				for(int i = 0; i < keys.Length; i++)
				{
					if (!keep.Contains(keys[i]))
					{
						Remove(keys[i]);
					}
					else if (!hasItemsToKeep)
					{
						hasItemsToKeep = true;
					}
				}

				keep.Clear();
			}

			hasSwept = true;
		}

Usage Example

Example #1
0
		public void FlashKeep()
		{
			Flash flash = new Flash();

			flash.Now("test1","hello");
			flash.Now("test2","hello");

			flash.Keep("test1");

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test1") );
			Assert.IsFalse( flash.ContainsKey("test2") );

			flash = new Flash(flash);
			flash.Sweep();

			Assert.IsTrue( flash.Count == 0 );

			flash.Now("test1","hello");
			flash.Now("test2","hello");

			flash.Keep();

			flash.Sweep();

			Assert.IsTrue( flash.ContainsKey("test1") );
			Assert.IsTrue( flash.ContainsKey("test2") );
		}
All Usage Examples Of Castle.MonoRail.Framework.Flash::Sweep