CodeIdentifiers.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // System.Xml.Serialization.CodeIdentifiers
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System;
  10. using System.Collections;
  11. namespace System.Xml.Serialization {
  12. public class CodeIdentifiers {
  13. #region Fields
  14. bool useCamelCasing;
  15. static Hashtable table = new Hashtable ();
  16. #endregion
  17. #region Constructors
  18. public CodeIdentifiers ()
  19. {
  20. }
  21. #endregion // Constructors
  22. #region Properties
  23. public bool UseCamelCasing {
  24. get { return useCamelCasing; }
  25. set { useCamelCasing = value; }
  26. }
  27. #endregion // Properties
  28. #region Methods
  29. public void Add (string identifier, object value)
  30. {
  31. table.Add (identifier, value);
  32. }
  33. [MonoTODO ("What does this do?")]
  34. public void AddReserved (string identifier)
  35. {
  36. throw new NotImplementedException ();
  37. }
  38. public void AddUnique (string identifier, object value)
  39. {
  40. Add (MakeUnique (identifier), value);
  41. }
  42. public void Clear ()
  43. {
  44. table.Clear ();
  45. }
  46. public bool IsInUse (string identifier)
  47. {
  48. return (table.ContainsKey (identifier));
  49. }
  50. public string MakeRightCase (string identifier)
  51. {
  52. if (UseCamelCasing)
  53. return CodeIdentifier.MakeCamel (identifier);
  54. else
  55. return CodeIdentifier.MakePascal (identifier);
  56. }
  57. public string MakeUnique (string identifier)
  58. {
  59. string uniqueIdentifier = identifier;
  60. int i = 1;
  61. while (IsInUse (uniqueIdentifier)) {
  62. uniqueIdentifier = String.Format ("{0}{1}", identifier, i.ToString ());
  63. i += 1;
  64. }
  65. return uniqueIdentifier;
  66. }
  67. public void Remove (string identifier)
  68. {
  69. table.Remove (identifier);
  70. }
  71. [MonoTODO ("What does this do?")]
  72. public void RemoveReserved (string identifier)
  73. {
  74. throw new NotImplementedException ();
  75. }
  76. [MonoTODO ("Need to determine how to do the conversion.")]
  77. public object ToArray (Type type)
  78. {
  79. throw new NotImplementedException ();
  80. }
  81. #endregion // Methods
  82. }
  83. }