| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // System.Xml.Serialization.CodeIdentifiers
- //
- // Author:
- // Tim Coleman ([email protected])
- //
- // Copyright (C) Tim Coleman, 2002
- //
- using System;
- using System.Collections;
- namespace System.Xml.Serialization {
- public class CodeIdentifiers {
- #region Fields
- bool useCamelCasing;
- Hashtable table = new Hashtable ();
- Hashtable reserved = new Hashtable ();
- #endregion
- #region Constructors
- public CodeIdentifiers ()
- {
- }
- #endregion // Constructors
- #region Properties
- public bool UseCamelCasing {
- get { return useCamelCasing; }
- set { useCamelCasing = value; }
- }
- #endregion // Properties
- #region Methods
- public void Add (string identifier, object value)
- {
- table.Add (identifier, value);
- }
- public void AddReserved (string identifier)
- {
- reserved.Add (identifier, identifier);
- }
- public string AddUnique (string identifier, object value)
- {
- string unique = MakeUnique (identifier);
- Add (unique, value);
- return unique;
- }
- public void Clear ()
- {
- table.Clear ();
- }
- public bool IsInUse (string identifier)
- {
- return (table.ContainsKey (identifier) || reserved.ContainsKey (identifier));
- }
- public string MakeRightCase (string identifier)
- {
- if (UseCamelCasing)
- return CodeIdentifier.MakeCamel (identifier);
- else
- return CodeIdentifier.MakePascal (identifier);
- }
- public string MakeUnique (string identifier)
- {
- string uniqueIdentifier = identifier;
- int i = 1;
- while (IsInUse (uniqueIdentifier)) {
- uniqueIdentifier = String.Format ("{0}{1}", identifier, i.ToString ());
- i += 1;
- }
- return uniqueIdentifier;
- }
- public void Remove (string identifier)
- {
- table.Remove (identifier);
- }
- public void RemoveReserved (string identifier)
- {
- reserved.Remove (identifier);
- }
- public object ToArray (Type type)
- {
- Array list = Array.CreateInstance (type, table.Count);
- table.CopyTo (list, 0);
- return list;
- }
- #endregion // Methods
- }
- }
|