2 // System.ComponentModel.TypeDescriptorTests test cases
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // (c) 2004 Novell, Inc. (http://www.ximian.com)
11 using System.Collections;
12 using System.ComponentModel;
13 using System.ComponentModel.Design;
14 using System.Globalization;
16 namespace MonoTests.System.ComponentModel
18 class MyDesigner: IDesigner
24 public IComponent Component {get{return null; }}
26 public DesignerVerbCollection Verbs {get{return null; }}
28 public void DoDefaultAction () { }
30 public void Initialize (IComponent component) { }
32 public void Dispose () { }
35 class MyOtherDesigner: IDesigner
37 public MyOtherDesigner()
41 public IComponent Component {get {return null; } }
42 public DesignerVerbCollection Verbs { get {return null; } }
43 public void DoDefaultAction () { }
44 public void Initialize (IComponent component) { }
45 public void Dispose () { }
50 public IComponent Component { get { return null; } }
52 public IContainer Container { get { return null; } }
54 public bool DesignMode { get { return true; } }
56 public string Name { get { return "TestName"; } set { } }
58 public object GetService (Type t)
60 if (t == typeof(ITypeDescriptorFilterService)) return new MyFilter ();
65 class MyFilter: ITypeDescriptorFilterService
67 public bool FilterAttributes (IComponent component,IDictionary attributes)
69 Attribute ea = new DefaultEventAttribute ("AnEvent");
70 attributes [ea.TypeId] = ea;
71 ea = new DefaultPropertyAttribute ("TestProperty");
72 attributes [ea.TypeId] = ea;
73 ea = new EditorAttribute ();
74 attributes [ea.TypeId] = ea;
78 public bool FilterEvents (IComponent component, IDictionary events)
80 events.Remove ("AnEvent");
84 public bool FilterProperties (IComponent component, IDictionary properties)
86 properties.Remove ("TestProperty");
91 class AnotherSite: ISite
93 public IComponent Component { get { return null; } }
95 public IContainer Container { get { return null; } }
97 public bool DesignMode { get { return true; } }
99 public string Name { get { return "TestName"; } set { } }
101 public object GetService (Type t)
103 if (t == typeof(ITypeDescriptorFilterService)) {
104 return new AnotherFilter ();
110 class NoFilterSite : ISite
112 public NoFilterSite () : this (null)
116 public NoFilterSite (IContainer container)
118 _container = container;
121 public IComponent Component {
125 public IContainer Container {
126 get { return _container; }
129 public bool DesignMode { get { return true; } }
131 public string Name { get { return "TestName"; } set { } }
133 public object GetService (Type t)
138 public IContainer _container;
141 class MyContainer : IContainer
143 public MyContainer ()
145 _components = new ComponentCollection (new IComponent [0]);
148 public ComponentCollection Components {
149 get { return _components; }
152 public void Add (IComponent component)
156 public void Add (IComponent component, string name)
160 public void Dispose ()
164 public void Remove (IComponent component)
168 private ComponentCollection _components;
171 class AnotherFilter: ITypeDescriptorFilterService
173 public bool FilterAttributes (IComponent component,IDictionary attributes) {
174 Attribute ea = new DefaultEventAttribute ("AnEvent");
175 attributes [ea.TypeId] = ea;
176 ea = new DefaultPropertyAttribute ("TestProperty");
177 attributes [ea.TypeId] = ea;
178 ea = new EditorAttribute ();
179 attributes [ea.TypeId] = ea;
183 public bool FilterEvents (IComponent component, IDictionary events) {
187 public bool FilterProperties (IComponent component, IDictionary properties) {
192 [DescriptionAttribute ("my test component")]
193 [DesignerAttribute (typeof(MyDesigner), typeof(int))]
194 public class MyComponent: Component
198 [DescriptionAttribute ("test")]
199 public event EventHandler AnEvent;
201 public event EventHandler AnotherEvent;
203 public MyComponent ()
207 public MyComponent (ISite site)
212 public MyComponent (IContainer container)
214 container.Add (this);
217 [DescriptionAttribute ("test")]
218 public virtual string TestProperty
221 set { prop = value; }
224 public string AnotherProperty
227 set { prop = value; }
231 [DescriptionAttribute ("my test derived component")]
232 [DesignerAttribute (typeof(MyOtherDesigner))]
233 public class MyDerivedComponent: MyComponent
237 public MyDerivedComponent ()
241 public MyDerivedComponent (ISite site) : base (site)
245 [DescriptionAttribute ("test derived")]
246 public override string TestProperty
249 set { prop = value; }
254 [DefaultProperty("AnotherProperty")]
255 [DefaultEvent("AnotherEvent")]
256 [DescriptionAttribute ("my test component")]
257 [DesignerAttribute (typeof(MyDesigner), typeof(int))]
258 public class AnotherComponent: Component {
261 [DescriptionAttribute ("test")]
262 public event EventHandler AnEvent;
264 public event EventHandler AnotherEvent;
266 public AnotherComponent () {
269 public AnotherComponent (ISite site) {
273 [DescriptionAttribute ("test")]
274 public string TestProperty {
276 set { prop = value; }
279 public string AnotherProperty {
281 set { prop = value; }
285 public interface ITestInterface
287 void TestFunction ();
290 public class TestClass
299 public struct TestStruct
304 public class TestCustomTypeDescriptor : ICustomTypeDescriptor
306 public string methods_called = "";
308 public void ResetMethodsCalled ()
313 public TypeConverter GetConverter()
315 return new StringConverter();
318 public EventDescriptorCollection GetEvents(Attribute[] attributes)
320 methods_called += "1";
324 public EventDescriptorCollection GetEvents()
326 methods_called += "2";
330 public string GetComponentName()
332 return "MyComponentnName";
335 public object GetPropertyOwner(PropertyDescriptor pd)
340 public AttributeCollection GetAttributes()
342 methods_called += "3";
346 public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
348 methods_called += "4";
349 return new PropertyDescriptorCollection(new PropertyDescriptor[0]);
352 public PropertyDescriptorCollection GetProperties()
354 methods_called += "5";
355 return new PropertyDescriptorCollection(new PropertyDescriptor[0]);
358 public object GetEditor(Type editorBaseType)
363 public PropertyDescriptor GetDefaultProperty()
365 methods_called += "6";
369 public EventDescriptor GetDefaultEvent()
371 methods_called += "7";
375 public string GetClassName()
377 return this.GetType().Name;
382 public class TypeDescriptorTests
384 MyComponent com = new MyComponent ();
385 MyComponent sitedcom = new MyComponent (new MySite ());
386 MyComponent nfscom = new MyComponent (new NoFilterSite (new MyContainer ()));
387 AnotherComponent anothercom = new AnotherComponent ();
390 public void TestICustomTypeDescriptor ()
392 TestCustomTypeDescriptor test = new TestCustomTypeDescriptor ();
394 PropertyDescriptorCollection props;
395 PropertyDescriptor prop;
396 EventDescriptorCollection events;
398 test.ResetMethodsCalled ();
399 props = TypeDescriptor.GetProperties (test);
400 Assert.AreEqual ("5", test.methods_called, "#1");
402 test.ResetMethodsCalled ();
403 props = TypeDescriptor.GetProperties (test, new Attribute[0]);
404 Assert.AreEqual ("4", test.methods_called, "#2");
406 test.ResetMethodsCalled ();
407 props = TypeDescriptor.GetProperties (test, new Attribute[0], false);
408 Assert.AreEqual ("4", test.methods_called, "#3");
410 test.ResetMethodsCalled ();
411 props = TypeDescriptor.GetProperties (test, false);
412 Assert.AreEqual ("5", test.methods_called, "#4");
414 test.ResetMethodsCalled ();
415 prop = TypeDescriptor.GetDefaultProperty (test);
416 Assert.AreEqual ("6", test.methods_called, "#5");
418 test.ResetMethodsCalled ();
419 events = TypeDescriptor.GetEvents (test);
420 Assert.AreEqual ("2", test.methods_called, "#6");
422 test.ResetMethodsCalled ();
423 events = TypeDescriptor.GetEvents (test, new Attribute[0]);
424 Assert.AreEqual ("1", test.methods_called, "#7");
426 test.ResetMethodsCalled ();
427 events = TypeDescriptor.GetEvents (test, false);
428 Assert.AreEqual ("2", test.methods_called, "#8");
432 public void TestCreateDesigner ()
434 IDesigner des = TypeDescriptor.CreateDesigner (com, typeof(int));
435 Assert.IsTrue (des is MyDesigner, "#1");
437 des = TypeDescriptor.CreateDesigner (com, typeof(string));
438 Assert.IsNull (des, "#2");
442 public void TestCreateEvent ()
444 EventDescriptor ed = TypeDescriptor.CreateEvent (typeof(MyComponent), "AnEvent", typeof(EventHandler), null);
445 Assert.AreEqual (typeof (MyComponent), ed.ComponentType, "#1");
446 Assert.AreEqual (typeof (EventHandler), ed.EventType, "#2");
447 Assert.IsTrue (ed.IsMulticast, "#3");
448 Assert.AreEqual ("AnEvent", ed.Name, "#4");
452 public void TestCreateProperty ()
454 PropertyDescriptor pd = TypeDescriptor.CreateProperty (typeof(MyComponent), "TestProperty", typeof(string), null);
455 Assert.AreEqual (typeof (MyComponent), pd.ComponentType, "#1");
456 Assert.AreEqual ("TestProperty", pd.Name, "#2");
457 Assert.AreEqual (typeof (string), pd.PropertyType, "#3");
458 Assert.IsFalse (pd.IsReadOnly, "#4");
460 pd.SetValue (com, "hi");
461 Assert.AreEqual ("hi", pd.GetValue (com), "#5");
465 public void TestGetAttributes ()
467 AttributeCollection col = TypeDescriptor.GetAttributes (typeof(MyComponent));
468 Assert.IsNotNull (col [typeof (DescriptionAttribute)], "#A1");
469 Assert.IsNotNull (col [typeof (DesignerAttribute)], "#A2");
470 Assert.IsNull (col [typeof (EditorAttribute)], "#A3");
472 col = TypeDescriptor.GetAttributes (com);
473 Assert.IsNotNull (col [typeof (DescriptionAttribute)], "#B1");
474 Assert.IsNotNull (col [typeof (DesignerAttribute)], "#B2");
475 Assert.IsNull (col [typeof (EditorAttribute)], "#B3");
477 col = TypeDescriptor.GetAttributes (sitedcom);
478 Assert.IsNotNull (col [typeof (DescriptionAttribute)], "#C1");
479 Assert.IsNotNull (col [typeof (DesignerAttribute)], "#C2");
480 Assert.IsNotNull (col [typeof (EditorAttribute)], "#C3");
482 col = TypeDescriptor.GetAttributes (nfscom);
483 Assert.IsNotNull (col [typeof (DescriptionAttribute)], "#D1");
484 Assert.IsNotNull (col [typeof (DesignerAttribute)], "#D2");
485 Assert.IsNull (col [typeof (EditorAttribute)], "#D3");
487 col = TypeDescriptor.GetAttributes (typeof (MyDerivedComponent));
488 Assert.IsNotNull (col [typeof (DesignerAttribute)], "#E1");
489 Assert.IsNotNull (col [typeof (DescriptionAttribute)], "#E2");
490 DesignerAttribute attribute = col[typeof(DesignerAttribute)] as DesignerAttribute;
491 Assert.IsNotNull (attribute, "#E3");
492 // there are multiple DesignerAttribute present and their order in the collection isn't deterministic
494 for (int i = 0; i < col.Count; i++) {
495 attribute = (col [i] as DesignerAttribute);
496 if (attribute != null) {
497 found = typeof(MyOtherDesigner).AssemblyQualifiedName == attribute.DesignerTypeName;
502 Assert.IsTrue (found, "#E4");
506 public void TestGetClassName ()
508 Assert.AreEqual (typeof(MyComponent).FullName, TypeDescriptor.GetClassName (com));
512 public void TestGetComponentName ()
515 // in MS.NET 2.0, GetComponentName no longer returns
516 // the type name if there's no custom typedescriptor
518 Assert.IsNull (TypeDescriptor.GetComponentName (com), "#1");
519 Assert.IsNull (TypeDescriptor.GetComponentName (com, false), "#2");
520 Assert.IsNull (TypeDescriptor.GetComponentName (new Exception ()), "#3");
521 Assert.IsNull (TypeDescriptor.GetComponentName (new Exception (), false), "#4");
522 Assert.IsNull (TypeDescriptor.GetComponentName (typeof (Exception)), "#4");
523 Assert.IsNull (TypeDescriptor.GetComponentName (typeof (Exception), false), "#6");
525 Assert.AreEqual ("MyComponent", TypeDescriptor.GetComponentName (com), "#1");
526 Assert.AreEqual ("MyComponent", TypeDescriptor.GetComponentName (com, false), "#2");
527 Assert.AreEqual ("Exception", TypeDescriptor.GetComponentName (new Exception ()), "#3");
528 Assert.AreEqual ("Exception", TypeDescriptor.GetComponentName (new Exception (), false), "#4");
529 Assert.IsNotNull (TypeDescriptor.GetComponentName (typeof (Exception)), "#5");
530 Assert.IsNotNull (TypeDescriptor.GetComponentName (typeof (Exception), false), "#6");
532 Assert.AreEqual ("TestName", TypeDescriptor.GetComponentName (sitedcom), "#7");
533 Assert.AreEqual ("TestName", TypeDescriptor.GetComponentName (sitedcom), "#8");
537 public void TestGetConverter ()
539 Assert.AreEqual (typeof (BooleanConverter), TypeDescriptor.GetConverter (typeof (bool)).GetType (), "#1");
540 Assert.AreEqual (typeof (ByteConverter), TypeDescriptor.GetConverter (typeof (byte)).GetType (), "#2");
541 Assert.AreEqual (typeof (SByteConverter), TypeDescriptor.GetConverter (typeof (sbyte)).GetType (), "#3");
542 Assert.AreEqual (typeof (StringConverter), TypeDescriptor.GetConverter (typeof (string)).GetType (), "#4");
543 Assert.AreEqual (typeof (CharConverter), TypeDescriptor.GetConverter (typeof (char)).GetType (), "#5");
544 Assert.AreEqual (typeof (Int16Converter), TypeDescriptor.GetConverter (typeof (short)).GetType (), "#6");
545 Assert.AreEqual (typeof (Int32Converter), TypeDescriptor.GetConverter (typeof (int)).GetType (), "#7");
546 Assert.AreEqual (typeof (Int64Converter), TypeDescriptor.GetConverter (typeof (long)).GetType (), "#8");
547 Assert.AreEqual (typeof (UInt16Converter), TypeDescriptor.GetConverter (typeof (ushort)).GetType (), "#9");
548 Assert.AreEqual (typeof (UInt32Converter), TypeDescriptor.GetConverter (typeof (uint)).GetType (), "#10");
549 Assert.AreEqual (typeof (UInt64Converter), TypeDescriptor.GetConverter (typeof (ulong)).GetType (), "#11");
550 Assert.AreEqual (typeof (SingleConverter), TypeDescriptor.GetConverter (typeof (float)).GetType (), "#12");
551 Assert.AreEqual (typeof (DoubleConverter), TypeDescriptor.GetConverter (typeof (double)).GetType (), "#13");
552 Assert.AreEqual (typeof (DecimalConverter), TypeDescriptor.GetConverter (typeof (decimal)).GetType (), "#14");
553 Assert.AreEqual (typeof (ArrayConverter), TypeDescriptor.GetConverter (typeof (Array)).GetType (), "#15");
554 Assert.AreEqual (typeof (CultureInfoConverter), TypeDescriptor.GetConverter (typeof (CultureInfo)).GetType (), "#16");
555 Assert.AreEqual (typeof (DateTimeConverter), TypeDescriptor.GetConverter (typeof (DateTime)).GetType (), "#17");
556 Assert.AreEqual (typeof (GuidConverter), TypeDescriptor.GetConverter (typeof (Guid)).GetType (), "#18");
557 Assert.AreEqual (typeof (TimeSpanConverter), TypeDescriptor.GetConverter (typeof (TimeSpan)).GetType (), "#19");
558 Assert.AreEqual (typeof (CollectionConverter), TypeDescriptor.GetConverter (typeof (ICollection)).GetType (), "#20");
560 // Tests from bug #71444
561 Assert.AreEqual (typeof (CollectionConverter), TypeDescriptor.GetConverter (typeof (IDictionary)).GetType (), "#21");
562 Assert.AreEqual (typeof (ReferenceConverter), TypeDescriptor.GetConverter (typeof (ITestInterface)).GetType (), "#22");
563 Assert.AreEqual (typeof (TypeConverter), TypeDescriptor.GetConverter (typeof (TestClass)).GetType (), "#23");
564 Assert.AreEqual (typeof (TypeConverter), TypeDescriptor.GetConverter (typeof (TestStruct)).GetType (), "#24");
566 Assert.AreEqual (typeof (TypeConverter), TypeDescriptor.GetConverter (new TestClass ()).GetType (), "#25");
567 Assert.AreEqual (typeof (TypeConverter), TypeDescriptor.GetConverter (new TestStruct ()).GetType (), "#26");
568 Assert.AreEqual (typeof (CollectionConverter), TypeDescriptor.GetConverter (new Hashtable ()).GetType (), "#27");
571 // Test from bug #76686
572 Assert.AreEqual (typeof (Int32Converter), TypeDescriptor.GetConverter ((int?) 1).GetType (), "#28");
577 public void TestGetDefaultEvent ()
579 EventDescriptor des = TypeDescriptor.GetDefaultEvent (typeof(MyComponent));
580 Assert.IsNull ( des, "#A");
582 des = TypeDescriptor.GetDefaultEvent (com);
583 Assert.IsNull (des, "#B");
585 des = TypeDescriptor.GetDefaultEvent (typeof(AnotherComponent));
586 Assert.IsNotNull (des, "#C1");
587 Assert.AreEqual ("AnotherEvent", des.Name, "#C2");
589 des = TypeDescriptor.GetDefaultEvent (anothercom);
590 Assert.IsNotNull (des, "#D1");
591 Assert.AreEqual ("AnotherEvent", des.Name, "#D2");
593 des = TypeDescriptor.GetDefaultEvent (sitedcom);
595 Assert.IsNull (des, "#E1");
597 Assert.IsNotNull (des, "#E1");
598 Assert.AreEqual ("AnotherEvent", des.Name, "#E2");
601 des = TypeDescriptor.GetDefaultEvent (new MyComponent(new AnotherSite ()));
602 Assert.IsNotNull (des, "#F1");
603 Assert.AreEqual ("AnEvent", des.Name, "#F2");
605 des = TypeDescriptor.GetDefaultEvent (new AnotherComponent(new AnotherSite ()));
606 Assert.IsNotNull (des, "#G1");
607 Assert.AreEqual ("AnEvent", des.Name, "#G2");
611 public void TestGetDefaultProperty ()
613 PropertyDescriptor des = TypeDescriptor.GetDefaultProperty (typeof(MyComponent));
614 Assert.IsNull (des, "#A");
616 des = TypeDescriptor.GetDefaultProperty (com);
617 Assert.IsNull (des, "#B");
619 des = TypeDescriptor.GetDefaultProperty (typeof(AnotherComponent));
620 Assert.IsNotNull (des, "#C1");
621 Assert.AreEqual ("AnotherProperty", des.Name, "#C2");
623 des = TypeDescriptor.GetDefaultProperty (anothercom);
624 Assert.IsNotNull (des, "#D1");
625 Assert.AreEqual ("AnotherProperty", des.Name, "#D2");
630 // throws NullReferenceException on MS.NET 1.x due to bug
631 // which is fixed in MS.NET 2.0
632 [NUnit.Framework.Category("NotDotNet")]
634 public void TestGetDefaultProperty2 ()
636 PropertyDescriptor des = TypeDescriptor.GetDefaultProperty (sitedcom);
637 Assert.IsNull (des, "#A");
639 des = TypeDescriptor.GetDefaultProperty (new MyComponent (new AnotherSite ()));
640 Assert.IsNotNull (des, "#B1");
641 Assert.AreEqual ("TestProperty", des.Name, "#B2");
643 des = TypeDescriptor.GetDefaultProperty (new AnotherComponent (new AnotherSite ()));
644 Assert.IsNotNull (des, "#C1");
645 Assert.AreEqual ("TestProperty", des.Name, "#C2");
647 des = TypeDescriptor.GetDefaultProperty (new AnotherComponent (new MySite ()));
648 Assert.IsNull (des, "#D");
652 public void TestGetEvents ()
654 EventDescriptorCollection col = TypeDescriptor.GetEvents (typeof(MyComponent));
655 Assert.AreEqual (3, col.Count, "#A1");
656 Assert.IsNotNull (col.Find ("AnEvent", true), "#A2");
657 Assert.IsNotNull (col.Find ("AnotherEvent", true), "#A3");
658 Assert.IsNotNull (col.Find ("Disposed", true), "#A4");
660 col = TypeDescriptor.GetEvents (com);
661 Assert.AreEqual (3, col.Count, "#B1");
662 Assert.IsNotNull (col.Find ("AnEvent", true), "#B2");
663 Assert.IsNotNull (col.Find ("AnotherEvent", true), "#B3");
664 Assert.IsNotNull (col.Find ("Disposed", true), "#B4");
666 col = TypeDescriptor.GetEvents (sitedcom);
667 Assert.AreEqual (2, col.Count, "#C1");
668 Assert.IsNotNull (col.Find ("AnotherEvent", true), "#C2");
669 Assert.IsNotNull (col.Find ("Disposed", true), "#C3");
671 col = TypeDescriptor.GetEvents (nfscom);
672 Assert.AreEqual (3, col.Count, "#D1");
673 Assert.IsNotNull (col.Find ("AnEvent", true), "#D2");
674 Assert.IsNotNull ( col.Find ("AnotherEvent", true), "#D3");
675 Assert.IsNotNull (col.Find ("Disposed", true), "#D4");
677 Attribute[] filter = new Attribute[] { new DescriptionAttribute ("test") };
679 col = TypeDescriptor.GetEvents (typeof(MyComponent), filter);
680 Assert.AreEqual (1, col.Count, "#E1");
681 Assert.IsNotNull (col.Find ("AnEvent", true), "#E2");
683 col = TypeDescriptor.GetEvents (com, filter);
684 Assert.AreEqual (1, col.Count, "#F1");
685 Assert.IsNotNull (col.Find ("AnEvent", true), "#F2");
687 col = TypeDescriptor.GetEvents (sitedcom, filter);
688 Assert.AreEqual (0, col.Count, "#G");
690 col = TypeDescriptor.GetEvents (nfscom, filter);
691 Assert.AreEqual (1, col.Count, "#H1");
692 Assert.IsNotNull (col.Find ("AnEvent", true), "#H2");
696 public void TestGetProperties ()
698 PropertyDescriptorCollection col = TypeDescriptor.GetProperties (typeof(MyComponent));
699 Assert.IsNotNull (col.Find ("TestProperty", true), "#A1");
700 Assert.IsNotNull ( col.Find ("AnotherProperty", true), "#A2");
702 col = TypeDescriptor.GetProperties (com);
703 Assert.IsNotNull (col.Find ("TestProperty", true), "#B1");
704 Assert.IsNotNull (col.Find ("AnotherProperty", true), "#B2");
706 col = TypeDescriptor.GetProperties (nfscom);
707 Assert.IsNotNull (col.Find ("TestProperty", true), "#C1");
708 Assert.IsNotNull (col.Find ("AnotherProperty", true), "#C2");
710 Attribute[] filter = new Attribute[] { new DescriptionAttribute ("test") };
712 col = TypeDescriptor.GetProperties (typeof(MyComponent), filter);
713 Assert.IsNotNull (col.Find ("TestProperty", true), "#D1");
714 Assert.IsNull (col.Find ("AnotherProperty", true), "#D2");
716 col = TypeDescriptor.GetProperties (com, filter);
717 Assert.IsNotNull (col.Find ("TestProperty", true), "#E1");
718 Assert.IsNull (col.Find ("AnotherProperty", true), "#E2");
720 col = TypeDescriptor.GetProperties (nfscom, filter);
721 Assert.IsNotNull (col.Find ("TestProperty", true), "#F1");
722 Assert.IsNull (col.Find ("AnotherProperty", true), "#F2");
727 // throws NullReferenceException on MS.NET 1.x due to bug
728 // which is fixed in MS.NET 2.0
729 [NUnit.Framework.Category("NotDotNet")]
731 public void TestGetProperties2 ()
733 PropertyDescriptorCollection col = TypeDescriptor.GetProperties (sitedcom);
734 Assert.IsNull (col.Find ("TestProperty", true), "#A1");
735 Assert.IsNotNull (col.Find ("AnotherProperty", true), "#A2");
737 Attribute[] filter = new Attribute[] { new DescriptionAttribute ("test") };
738 col = TypeDescriptor.GetProperties (sitedcom, filter);
739 Assert.IsNull (col.Find ("TestProperty", true), "#B1");
740 Assert.IsNull (col.Find ("AnotherProperty", true), "#B2");
743 [TypeConverter (typeof (TestConverter))]
744 class TestConverterClass {
747 class TestConverter : TypeConverter {
750 public TestConverter (Type type)
757 public void TestConverterCtorWithArgument ()
759 TypeConverter t = TypeDescriptor.GetConverter (typeof (TestConverterClass));
760 Assert.IsNotNull (t.GetType (), "#A1");
761 Assert.AreEqual (typeof (TestConverter), t.GetType (), "#A2");
762 TestConverter converter = (TestConverter) t;
763 Assert.AreEqual (typeof (TestConverterClass), converter.Type, "#B");
767 public void GetPropertiesIgnoreIndexers ()
769 PropertyDescriptorCollection pc =
770 TypeDescriptor.GetProperties (typeof (string));
771 // There are two string properties: Length and Chars.
772 // Chars is an indexer.
774 // Future version of CLI might contain some additional
775 // properties. In that case simply increase the
776 // number. (Also, it is fine to just remove #2.)
777 Assert.AreEqual (1, pc.Count, "#1");
778 Assert.AreEqual ("Length", pc [0].Name, "#2");