annotate EnumTools.cs @ 74:726731c78414

Re #37: Add event to indicate change of translation * Add event and trigger when current language value changes
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Apr 2010 14:56:17 +0000
parents 8fe11cd7d3bf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (XmlTools.cs) is a part of the IBBoard library and is copyright 2009 IBBoard
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System;
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 public class EnumTools
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// <summary>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// Takes a string and parses it as the required enum, returning the typed enum object. Parsing is case-insensitive. Throws a <code>ArgumentException</code> if the argument is not a valid enum value.
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 /// </summary>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 /// <param name="enumString">
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 /// The enum text string to parse
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 /// </param>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <returns>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// A typed enum value parsed from the text string
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 /// </returns>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 public static T ParseEnum<T>(string enumString)
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 return ParseEnum<T>(enumString, true);
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 }
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 /// <summary>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 /// Takes a string and parses it as the required enum, returning the typed enum object. Parsing can be case-sensitive or case-insensitive. Throws a <code>ArgumentException</code> if the argument is not a valid enum value.
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 /// </summary>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 /// <param name="enumString">
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 /// The enum text string to parse
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 /// </param>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 /// <param name="ignoreCase">
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 /// <code>True</code> if parsing should be case-insensitive, else <code>false</code>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 /// </param>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 /// <returns>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 /// A typed enum value parsed from the text string
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 /// </returns>
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 public static T ParseEnum<T>(string enumString, bool ignoreCase)
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 return (T) Enum.Parse(typeof (T), enumString, ignoreCase);
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
8fe11cd7d3bf Re #25: Enum parsing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }