Castle.MonoRail.Framework.Services.DefaultControllerTree.AddController C# (CSharp) 메소드

AddController() 공개 메소드

Register a controller on the tree. If the specified area name matches the current node, the controller is register on the node itself, otherwise on the right or on the left node.
Note that the controller is an object. That allows different implementation of a controller factory to register different representation of what a controller is (a name, a descriptor etc)
public AddController ( String areaName, String controllerName, Type controller ) : void
areaName String The area name, or String.Empty
controllerName String The controller name
controller System.Type The controller representation
리턴 void
		public void AddController(String areaName, String controllerName, Type controller)
		{
			if (areaName == null) throw new ArgumentNullException("areaName");
			if (controllerName == null) throw new ArgumentNullException("controllerName");
			if (controller == null) throw new ArgumentNullException("controller");

			int cmp = String.Compare(areaName, area, true);

			if (cmp == 0)
			{
				// If it's the same area, register the controller
				controllers[controllerName] = controller;
			}
			else
			{
				// Otherwise, check if the controller should be registered
				// on the left or on the right
				
				DefaultControllerTree node;

				if (cmp < 0)
				{
					if (left == null)
					{
						left = new DefaultControllerTree(areaName);
					}
					node = left;
				}
				else
				{
					if (right == null)
					{
						right = new DefaultControllerTree(areaName);
					}
					node = right;
				}

				node.AddController(areaName, controllerName, controller);
			}
		}

Usage Example

예제 #1
0
		public void EmptyArea()
		{
			DefaultControllerTree tree = new DefaultControllerTree();
			tree.AddController("", "home", typeof(HomeController));
			tree.AddController("", "contact", typeof(ContactController));
			tree.AddController("", "cart", typeof(CartController));

			Assert.AreEqual( typeof(HomeController), tree.GetController("", "home") );
			Assert.AreEqual( typeof(ContactController), tree.GetController("", "contact") );
			Assert.AreEqual( typeof(CartController), tree.GetController("", "cart") );
		}
All Usage Examples Of Castle.MonoRail.Framework.Services.DefaultControllerTree::AddController