5 // Chris J Breisch (cjbreisch@altavista.net)
6 // Dennis Hayes (dennish@raytek.com)
8 // (C) 2002 Chris J Breisch
10 /* Copyright (c) 2002-2003 Mainsoft Corporation.
11 * Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 * DEALINGS IN THE SOFTWARE.
33 using System.ComponentModel;
35 namespace Microsoft.VisualBasic.CompilerServices
37 [StandardModule, EditorBrowsable(EditorBrowsableState.Never)]
38 sealed public class CharType {
39 private CharType () {}
42 * The method converts given object to char by the following logic:
43 * 1. If input object is null - return '\0'
44 * 2. If input object is String - run FromString method
45 * 3. Otherwise run .NET default conversion - Convert.ToChar
46 * @param value - The object that going to be converted
47 * @return char The char value that converted from the source object
48 * @see system.Convert#ToChar
50 public static char FromObject(object Value) {
55 return FromString((string)Value);
57 //Mainsoft code creates a new execption, but that is just to convert from java execption to .net execption
58 return Convert.ToChar(Value);
62 * The method returns first character of the input string. If input string
63 * is null or empty return it returns '\0'
64 * @param str - The string that converted to char
65 * @return char The value that extracted from the input string.
67 public static char FromString(string Value) {
68 if (Value == null || Value.Length == 0)
71 return Value.ToCharArray()[0];