2 // System.Xml.Serialization.CodeIdentifiers
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
11 using System.Collections;
\r
13 namespace System.Xml.Serialization {
\r
14 public class CodeIdentifiers {
\r
18 bool useCamelCasing;
\r
19 Hashtable table = new Hashtable ();
\r
20 Hashtable reserved = new Hashtable ();
\r
24 #region Constructors
\r
26 public CodeIdentifiers ()
\r
30 #endregion // Constructors
\r
34 public bool UseCamelCasing {
\r
35 get { return useCamelCasing; }
\r
36 set { useCamelCasing = value; }
\r
39 #endregion // Properties
\r
43 public void Add (string identifier, object value)
\r
45 table.Add (identifier, value);
\r
48 public void AddReserved (string identifier)
\r
50 reserved.Add (identifier, identifier);
\r
53 public string AddUnique (string identifier, object value)
\r
55 string unique = MakeUnique (identifier);
\r
56 Add (unique, value);
\r
60 public void Clear ()
\r
65 public bool IsInUse (string identifier)
\r
67 return (table.ContainsKey (identifier) || reserved.ContainsKey (identifier));
\r
70 public string MakeRightCase (string identifier)
\r
73 return CodeIdentifier.MakeCamel (identifier);
\r
75 return CodeIdentifier.MakePascal (identifier);
\r
78 public string MakeUnique (string identifier)
\r
80 string uniqueIdentifier = identifier;
\r
83 while (IsInUse (uniqueIdentifier)) {
\r
84 uniqueIdentifier = String.Format ("{0}{1}", identifier, i.ToString ());
\r
88 return uniqueIdentifier;
\r
91 public void Remove (string identifier)
\r
93 table.Remove (identifier);
\r
96 public void RemoveReserved (string identifier)
\r
98 reserved.Remove (identifier);
\r
101 public object ToArray (Type type)
\r
103 Array list = Array.CreateInstance (type, table.Count);
\r
104 table.CopyTo (list, 0);
\r
108 #endregion // Methods
\r