Add() 공개 메소드

public Add ( System.ComponentModel.EventDescriptor value ) : int
value System.ComponentModel.EventDescriptor
리턴 int
예제 #1
0
 public static EventDescriptorCollection GetEvents
     (Type componentType, Attribute[] attributes)
 {
     lock (typeof(TypeDescriptor))
     {
         TypeElement element = GetOrCreateElement(componentType);
         if (element.events != null)
         {
             return(element.events);
         }
         EventDescriptorCollection coll;
         coll = new EventDescriptorCollection(null);
         foreach (EventInfo eventInfo in componentType.GetEvents())
         {
             coll.Add(new BuiltinEventDescriptor
                          (eventInfo, attributes));
         }
         element.events = coll;
         return(coll);
     }
 }
		private void AssertReadOnly (EventDescriptorCollection descriptors, string testCase)
		{
			MockEventDescriptor desc = new MockEventDescriptor (
				"Date", "NOW");

			try {
				descriptors.Add (desc);
				Assert.Fail (testCase + "#1");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				descriptors.Add (null);
				Assert.Fail (testCase + "#2");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				descriptors.Clear ();
				Assert.Fail (testCase + "#3");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				descriptors.Insert (0, desc);
				Assert.Fail (testCase + "#4");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				descriptors.Insert (0, null);
				Assert.Fail (testCase + "#5");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				descriptors.Remove (desc);
				Assert.Fail (testCase + "#6");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				descriptors.Remove (null);
				Assert.Fail (testCase + "#7");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				descriptors.RemoveAt (0);
				Assert.Fail (testCase + "#8");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			IList list = (IList) descriptors;
			Assert.IsTrue (((IList) descriptors).IsReadOnly, testCase + "#9");
#if NET_2_0
			Assert.IsTrue (((IList) descriptors).IsFixedSize, testCase + "#10");
#else
			Assert.IsFalse (((IList) descriptors).IsFixedSize, testCase + "#10");
#endif

			try {
				list.Add (desc);
				Assert.Fail (testCase + "#11");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				list.Add (null);
				Assert.Fail (testCase + "#12");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				list.Clear ();
				Assert.Fail (testCase + "#13");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				list.Insert (0, desc);
				Assert.Fail (testCase + "#14");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				list.Insert (0, null);
				Assert.Fail (testCase + "#15");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				list.Remove (desc);
				Assert.Fail (testCase + "#16");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				list.Remove (null);
				Assert.Fail (testCase + "#17");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				list.RemoveAt (0);
				Assert.Fail (testCase + "#18");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			try {
				list[0] = desc;
				Assert.Fail (testCase + "#19");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}

			// ensure read-only check if performed before value is checked
			try {
				list[0] = null;
				Assert.Fail (testCase + "#20");
			} catch (NotSupportedException) {
				// read-only collection cannot be modified
			}
		}
	public static EventDescriptorCollection GetEvents
				(Type componentType, Attribute[] attributes)
			{
				lock(typeof(TypeDescriptor))
				{
					TypeElement element = GetOrCreateElement(componentType);
					if(element.events != null)
					{
						return element.events;
					}
					EventDescriptorCollection coll;
					coll = new EventDescriptorCollection(null);
					foreach(EventInfo eventInfo in componentType.GetEvents())
					{
						coll.Add(new BuiltinEventDescriptor
									(eventInfo, attributes));
					}
					element.events = coll;
					return coll;
				}
			}
		EventDescriptorCollection ITypeDescriptionProvider.GetEvents()
		{
			EventDescriptorCollection col1 = Provider.GetEvents();
			EventDescriptorCollection col2 = BaseTypeDescriptor.GetEvents();

			EventDescriptorCollection col  = new EventDescriptorCollection(new EventDescriptor[0]);

			foreach (EventDescriptor ed in col1)
				col.Add(ed);

			foreach (EventDescriptor ed in col2)
				if (col.Find(ed.Name, false) == null)
					col.Add(ed);

			return col;
		}