Inheritance: System.ComponentModel.Component
コード例 #1
0
ファイル: TypeDescriptorTests.cs プロジェクト: user277/mono
		public void TestRemoveProvider_Provider_Instance_3 ()
		{
			var instance = new MyComponent ();
			var provider = new MyTypeDescriptionProvider ();
			bool refreshedCalled = false;
			bool refreshedCorrectComponentChanged = false;
			bool refreshedCorrectTypeChanged = false;

			RefreshEventHandler handler = (RefreshEventArgs args) => {
				refreshedCalled = true;
				refreshedCorrectComponentChanged = args.ComponentChanged == instance;
				refreshedCorrectTypeChanged = args.TypeChanged == typeof (MyComponent);
			};

			try {
				TypeDescriptor.Refreshed += handler;

				TypeDescriptor.RemoveProvider (provider, instance);
				Assert.AreEqual (true, refreshedCalled, "#A1");
				Assert.AreEqual (true, refreshedCorrectComponentChanged, "#A2");
				Assert.AreEqual (true, refreshedCorrectTypeChanged, "#A3");
			} finally {
				TypeDescriptor.Refreshed -= handler;
			}
		}
コード例 #2
0
ファイル: ContainerTest.cs プロジェクト: nslAnil/mono
		[Test] // bug #522474
		public void Dispose_Recursive ()
		{
			MyComponent comp = new MyComponent ();
			Container container = comp.CreateContainer ();
			comp.Dispose ();
			Assert.AreEqual (0, container.Components.Count);
		}
コード例 #3
0
ファイル: TypeDescriptorTests.cs プロジェクト: user277/mono
		public void TestGetProvider_Instance_2 ()
		{
			var instance = new MyComponent ();
			TypeDescriptionProvider provider = TypeDescriptor.GetProvider (instance);
			Assert.IsNotNull (provider, "#A1");
			provider = new MyTypeDescriptionProvider ("One");

			try {
				TypeDescriptor.AddProvider (provider, instance);
				ICustomTypeDescriptor descriptor = provider.GetTypeDescriptor (instance);
				Assert.IsNotNull (descriptor, "#B1");
				Assert.AreEqual ("One", descriptor.GetClassName (), "#B1-1");
			} finally {
				TypeDescriptor.RemoveProvider (provider, instance);
			}
		}
コード例 #4
0
ファイル: TypeDescriptorTests.cs プロジェクト: user277/mono
		public void TestAddProvider_Provider_Instance_4 ()
		{
			var instance = new MyComponent ();
			var providers = new MyTypeDescriptionProvider[] {
				new MyTypeDescriptionProvider ("One"),
				new MyTypeDescriptionProvider ("Two"),
				new MyTypeDescriptionProvider ("Three"),
				new MyTypeDescriptionProvider ("Four")
			};

			try {
				TypeDescriptionProvider provider;
				ICustomTypeDescriptor descriptor;

				TypeDescriptor.AddProvider (providers[0], instance);
				provider = TypeDescriptor.GetProvider (instance);
				Assert.IsNotNull (provider, "#A1");
				descriptor = provider.GetTypeDescriptor (instance.GetType (), instance);
				Assert.IsNotNull (descriptor, "#A1-1");
				Assert.AreEqual ("One", descriptor.GetClassName (), "#A1-2");
				Assert.AreEqual (false, providers[0].CreateInstanceCalled, "#A1-3");

				descriptor.GetProperties ();

				TypeDescriptor.AddProvider (providers[1], instance);
				provider = TypeDescriptor.GetProvider (instance);
				Assert.IsNotNull (provider, "#B1");
				descriptor = provider.GetTypeDescriptor (instance.GetType (), instance);
				Assert.IsNotNull (descriptor, "#B1-1");
				Assert.AreEqual ("Two", descriptor.GetClassName (), "#B1-2");

				// Providers are stored in a stack according to docs, but it's in reality
				// a FIFO linked list
				TypeDescriptor.AddProvider (providers[0], instance);
				TypeDescriptor.AddProvider (providers[0], instance);
				provider = TypeDescriptor.GetProvider (instance);
				Assert.IsNotNull (provider, "#C1");
				descriptor = provider.GetTypeDescriptor (instance.GetType (), instance);
				Assert.IsNotNull (descriptor, "#C1-1");
				Assert.AreEqual ("One", descriptor.GetClassName (), "#C1-2");

				TypeDescriptor.RemoveProvider (providers[0], instance);
				provider = TypeDescriptor.GetProvider (instance);
				Assert.IsNotNull (provider, "#D1");
				descriptor = provider.GetTypeDescriptor (instance.GetType (), instance);
				Assert.IsNotNull (descriptor, "#D1-1");
				Assert.AreEqual ("One", descriptor.GetClassName (), "#D1-2");

				TypeDescriptor.RemoveProvider (providers[0], instance);
				provider = TypeDescriptor.GetProvider (instance);
				Assert.IsNotNull (provider, "#E1");
				descriptor = provider.GetTypeDescriptor (instance.GetType (), instance);
				Assert.IsNotNull (descriptor, "#E1-1");
				Assert.AreEqual ("Two", descriptor.GetClassName (), "#E1-2");

			} finally {
				TypeDescriptor.RemoveProvider (providers[0], instance);
				TypeDescriptor.RemoveProvider (providers[1], instance);
				TypeDescriptor.RemoveProvider (providers[2], instance);
				TypeDescriptor.RemoveProvider (providers[3], instance);
			}
		}
コード例 #5
0
ファイル: TypeDescriptorTests.cs プロジェクト: user277/mono
		public void GetProperties_Order ()
		{
			MyComponent com = new MyComponent (new MyContainer ());

			PropertyDescriptorCollection col = TypeDescriptor.GetProperties (com);
			Assert.AreEqual (8, col.Count, "#1");
			Assert.AreEqual ("TestProperty", col [0].Name, "#2");
			Assert.AreEqual ("AnotherProperty", col [1].Name, "#3");
			Assert.AreEqual ("YetAnotherProperty", col [2].Name, "#4");
			Assert.AreEqual ("Name", col [3].Name, "#5");
			Assert.AreEqual ("Address", col [4].Name, "#6");
			Assert.AreEqual ("Country", col [5].Name, "#7");
			Assert.AreEqual ("Site", col [6].Name, "#8");
			Assert.AreEqual ("Container", col [7].Name, "#9");
		}
コード例 #6
0
ファイル: TypeDescriptorTests.cs プロジェクト: user277/mono
		public void TestGetReflectionType_Instance_2 ()
		{
			string s = "string";
			Type type = TypeDescriptor.GetReflectionType (s);
			Assert.IsNotNull (type, "#A1");
			Assert.AreEqual (typeof (string), type, "#A1-1");

			var mc = new MyComponent ();
			type = TypeDescriptor.GetReflectionType (mc);
			Assert.IsNotNull (type, "#B1");
			Assert.AreEqual (typeof (MyComponent), type, "#B1-1");

			var l = new List<string> ();
			type = TypeDescriptor.GetReflectionType (l);
			Assert.IsNotNull (type, "#C1");
			Assert.AreEqual (typeof (List<string>), type, "#C1-1");

			IList il = new List<string> ();
			type = TypeDescriptor.GetReflectionType (il);
			Assert.IsNotNull (type, "#D1");
			Assert.AreEqual (typeof (List<string>), type, "#D1-1");

			IDictionary id = new Dictionary<string, object> ();
			type = TypeDescriptor.GetReflectionType (id);
			Assert.IsNotNull (type, "#E1");
			Assert.AreEqual (typeof (Dictionary<string,object>), type, "#E1-1");

			object o = 1;
			type = TypeDescriptor.GetReflectionType (o);
			Assert.IsNotNull (type, "#F1");
			Assert.AreEqual (typeof (int), type, "#F1-1");
		}
コード例 #7
0
ファイル: TypeDescriptorTests.cs プロジェクト: nlhepler/mono
		public void GetProperties_Order ()
		{
#if MOBILE
			// Component.Container will be be linked out (when using Link SDK) if unused
			Assert.Null (new Component ().Container, "pre-test");
#endif
			MyComponent com = new MyComponent (new MyContainer ());

			PropertyDescriptorCollection col = TypeDescriptor.GetProperties (com);
			Assert.AreEqual (8, col.Count, "#1");
			Assert.AreEqual ("TestProperty", col [0].Name, "#2");
			Assert.AreEqual ("AnotherProperty", col [1].Name, "#3");
			Assert.AreEqual ("YetAnotherProperty", col [2].Name, "#4");
			Assert.AreEqual ("Name", col [3].Name, "#5");
			Assert.AreEqual ("Address", col [4].Name, "#6");
			Assert.AreEqual ("Country", col [5].Name, "#7");
			Assert.AreEqual ("Site", col [6].Name, "#8");
			Assert.AreEqual ("Container", col [7].Name, "#9");
		}