当前位置: 首页>>代码示例>>C#>>正文


C# ServiceContainer.RemoveService方法代码示例

本文整理汇总了C#中System.ComponentModel.Design.ServiceContainer.RemoveService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.RemoveService方法的具体用法?C# ServiceContainer.RemoveService怎么用?C# ServiceContainer.RemoveService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.Design.ServiceContainer的用法示例。


在下文中一共展示了ServiceContainer.RemoveService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveService

		[Test] // RemoveService (Type, Boolean)
		public void RemoveService2_ServiceType_Null ()
		{
			ServiceContainer sc = new ServiceContainer ();

			try {
				sc.RemoveService ((Type) null, false);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.AreEqual ("serviceType", ex.ParamName, "#A5");
			}

			try {
				sc.RemoveService ((Type) null, true);
				Assert.Fail ("#B1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.AreEqual ("serviceType", ex.ParamName, "#B5");
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:25,代码来源:ServiceContainerTest.cs

示例2: NestedContainers

        public void NestedContainers() {
            Class1 class1 = new Class1();
            Class2 class2 = new Class2();
            Class3 class3 = new Class3();
            Class1 class1a = new Class1();

            ServiceContainer parentContainer = new ServiceContainer();
            parentContainer.AddService(typeof(IInterface1), class1);

            ServiceContainer childContainer = new ServiceContainer(parentContainer);
            childContainer.AddService(typeof(IInterface2), class2);

            // child container returns what it contains and what its parent contains
            Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1)));
            Assert.AreSame(class2, childContainer.GetService(typeof(IInterface2)));
            Assert.IsNull(childContainer.GetService(typeof(IInterface3)));

            // parent container only returns what it contains
            Assert.IsNull(parentContainer.GetService(typeof(IInterface2)));

            // add a service to the parent, and it becomes available to the child
            parentContainer.AddService(typeof(IInterface3), class3);
            Assert.AreSame(class3, childContainer.GetService(typeof(IInterface3)));
            Assert.AreSame(class3, parentContainer.GetService(typeof(IInterface3)));

            // remove a service from the parent, and it is no longer available to the child
            parentContainer.RemoveService(typeof(IInterface3));
            Assert.IsNull(childContainer.GetService(typeof(IInterface3)));
            Assert.IsNull(parentContainer.GetService(typeof(IInterface3)));

            // remove a service from the child container but not the parent container
            childContainer.RemoveService(typeof(IInterface1));
            Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1)));
            Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1)));

            // add an implementation to the child container and it overrides the parent container
            childContainer.AddService(typeof(IInterface1), class1a);
            Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1)));
            Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1)));

            // remove implementation from the child container, and the implementation in the parent
            // container is used again in the child container
            childContainer.RemoveService(typeof(IInterface1));
            Assert.AreSame(class1, childContainer.GetService(typeof(IInterface1)));
            Assert.AreSame(class1, parentContainer.GetService(typeof(IInterface1)));

            // remove implementation in the child container using promotion 
            childContainer.RemoveService(typeof(IInterface1), true);
            Assert.IsNull(childContainer.GetService(typeof(IInterface1)));
            Assert.IsNull(parentContainer.GetService(typeof(IInterface1)));

            // add implementation to both parent and child container, and then remove from child using
            // promotion, the implementation left in the child will remain
            parentContainer.AddService(typeof(IInterface1), class1);
            childContainer.AddService(typeof(IInterface1), class1a);
            childContainer.RemoveService(typeof(IInterface1), true);
            Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1)));
            Assert.IsNull(parentContainer.GetService(typeof(IInterface1)));

            // remove using promotion again and the implementation remains in the child
            childContainer.RemoveService(typeof(IInterface1), true);
            Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1)));
            Assert.AreSame(class1a, childContainer.GetService(typeof(IInterface1)));
            Assert.IsNull(parentContainer.GetService(typeof(IInterface1)));

            // remove without promotion and the instance is gone in the child
            childContainer.RemoveService(typeof(IInterface1), false);
            Assert.IsNull(childContainer.GetService(typeof(IInterface1)));
            Assert.IsNull(parentContainer.GetService(typeof(IInterface1)));
        }
开发者ID:matthewc-mps-aust,项目名称:quokka,代码行数:70,代码来源:ServiceProviderTests.cs


注:本文中的System.ComponentModel.Design.ServiceContainer.RemoveService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。