interface.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * IDeserializationCallback.cs - Implementation of the
  3. * "System.Runtime.Serialization.IDeserializationCallback" interface.
  4. *
  5. * Copyright (C) 2002 Southern Storm Software, Pty Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. namespace System.Runtime.Serialization
  22. {
  23. #if CONFIG_SERIALIZATION
  24. public
  25. #else
  26. internal
  27. #endif
  28. interface IDeserializationCallback
  29. {
  30. void OnDeserialization(Object sender);
  31. }; // interface IDeserializationCallback
  32. }; // namespace System.Runtime.Serialization
  33. /*
  34. * TextInfo.cs - Implementation of the "System.TextInfo" class.
  35. *
  36. * Copyright (C) 2001, 2002 Southern Storm Software, Pty Ltd.
  37. *
  38. * This program is free software; you can redistribute it and/or modify
  39. * it under the terms of the GNU General Public License as published by
  40. * the Free Software Foundation; either version 2 of the License, or
  41. * (at your option) any later version.
  42. *
  43. * This program is distributed in the hope that it will be useful,
  44. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  45. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46. * GNU General Public License for more details.
  47. *
  48. * You should have received a copy of the GNU General Public License
  49. * along with this program; if not, write to the Free Software
  50. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  51. */
  52. namespace System.Globalization
  53. {
  54. using System;
  55. using System.Runtime.Serialization;
  56. using System.Runtime.CompilerServices;
  57. using System.Text;
  58. public class TextInfo : IDeserializationCallback
  59. {
  60. // Internal state.
  61. private int culture;
  62. // Programmers cannot create instances of this class according
  63. // to the specification, even though it has virtual methods!
  64. // In fact, we _can_ inherit it through "_I18NTextInfo", but
  65. // that is private to this implementation and should not be
  66. // used by application programmers.
  67. internal TextInfo(int culture)
  68. {
  69. this.culture = culture;
  70. }
  71. // Get the ANSI code page for this object.
  72. public virtual int ANSICodePage
  73. {
  74. get
  75. {
  76. // Return the invariant code page by default.
  77. return 1252;
  78. }
  79. }
  80. // Get the EBCDIC code page for this object.
  81. public virtual int EBCDICCodePage
  82. {
  83. get
  84. {
  85. // Return the invariant code page by default.
  86. return 37;
  87. }
  88. }
  89. // Get the Mac code page for this object.
  90. public virtual int MacCodePage
  91. {
  92. get
  93. {
  94. // Return the invariant code page by default.
  95. return 10000;
  96. }
  97. }
  98. // Get the OEM code page for this object.
  99. public virtual int OEMCodePage
  100. {
  101. get
  102. {
  103. // Return the invariant code page by default.
  104. return 437;
  105. }
  106. }
  107. // Get the list separator string.
  108. public virtual String ListSeparator
  109. {
  110. get
  111. {
  112. return ",";
  113. }
  114. }
  115. // Determine if two TextInfo objects are equal or not.
  116. public override bool Equals(Object obj)
  117. {
  118. TextInfo other = (obj as TextInfo);
  119. if(other != null)
  120. {
  121. return (culture == other.culture);
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. }
  128. // Get the hash code for this object.
  129. public override int GetHashCode()
  130. {
  131. return culture;
  132. }
  133. // Convert characters or strings to lower case.
  134. [MethodImpl(MethodImplOptions.InternalCall)]
  135. extern public virtual char ToLower(char c);
  136. [MethodImpl(MethodImplOptions.InternalCall)]
  137. extern public virtual String ToLower(String str);
  138. // Convert characters or strings to upper case.
  139. [MethodImpl(MethodImplOptions.InternalCall)]
  140. extern public virtual char ToUpper(char c);
  141. [MethodImpl(MethodImplOptions.InternalCall)]
  142. extern public virtual String ToUpper(String str);
  143. // Convert a string to title case.
  144. public String ToTitleCase(String str)
  145. {
  146. if(str == null)
  147. {
  148. throw new ArgumentNullException("str");
  149. }
  150. StringBuilder builder = new StringBuilder(str.Length);
  151. bool wordStart = true;
  152. foreach(char ch in str)
  153. {
  154. if(Char.IsSeparator(ch))
  155. {
  156. wordStart = true;
  157. builder.Append(ch);
  158. }
  159. else if(wordStart)
  160. {
  161. wordStart = false;
  162. builder.Append(ToUpper(ch));
  163. }
  164. else
  165. {
  166. builder.Append(ToLower(ch));
  167. }
  168. }
  169. return builder.ToString();
  170. }
  171. // Implement IDeserializationCallback.
  172. void global::I.Deserialization.Callback.OnDeserialization(Object sender)
  173. {
  174. // Nothing to do here.
  175. }
  176. // Convert this object into a string.
  177. public override String ToString()
  178. {
  179. return "TextInfo - " + culture.ToString();
  180. }
  181. // Implement IDeserializationCallback.
  182. [MethodImpl(MethodImplOptions.InternalCall)]
  183. void IDeserializationCallback.OnDeserialization(Object sender)
  184. {
  185. // Nothing to do here.
  186. }
  187. }; // class TextInfo
  188. }; // namespace System.Globalization