2 // TypeDisplayerFactory.cs: Factory for TypeDisplayer objects
4 // Author: Jonathan Pryor (jonpryor@vt.edu)
6 // (C) 2002 Jonathan Pryor
8 // Permission is hereby granted, free of charge, to any
9 // person obtaining a copy of this software and associated
10 // documentation files (the "Software"), to deal in the
11 // Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software,
14 // and to permit persons to whom the Software is furnished to
15 // do so, subject to the following conditions:
17 // The above copyright notice and this permission notice
18 // shall be included in all copies or substantial portions
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
23 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
34 using System.Diagnostics;
35 using System.Reflection;
37 using System.Text.RegularExpressions;
39 namespace Mono.TypeReflector
41 public sealed class TypeDisplayerFactory
43 private static IDictionary entries = new Hashtable ();
45 public static void Add (string key, Type value)
48 entries.Add (key, value);
52 private static TypeDisplayer CreateInstance (Type type, TextWriter writer)
54 // Will work when Activator.CreateInstance works properly.
55 #if HAVE_WORKING_ACTIVATOR_CREATE_INSTANCE
56 return (TypeDisplayer) Activator.CreateInstance (type,
57 new object[]{writer});
59 // Look up constructor and invoke ourselves...
60 ConstructorInfo ctor =
61 type.GetConstructor(new Type[]{typeof(TextWriter)});
64 return (TypeDisplayer) ctor.Invoke(new object[]{writer});
68 public static TypeDisplayer Create (string key, TextWriter writer)
73 type = (Type) entries[key];
76 type = typeof (ExplicitTypeDisplayer);
77 return CreateInstance (type, writer);
84 public static void Remove (string key)
91 public static ICollection Keys {