Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
EnumMap.cs
Go to the documentation of this file.
1 #region Header Licence
2 // ---------------------------------------------------------------------
3 //
4 // Copyright (c) 2009 Alexandre Mutel and Microsoft Corporation.
5 // All rights reserved.
6 //
7 // This code module is part of NShader, a plugin for visual studio
8 // to provide syntax highlighting for shader languages (hlsl, glsl, cg)
9 //
10 // ------------------------------------------------------------------
11 //
12 // This code is licensed under the Microsoft Public License.
13 // See the file License.txt for the license details.
14 // More info on: http://nshader.codeplex.com
15 //
16 // ------------------------------------------------------------------
17 #endregion
18 using System;
19 using System.Collections.Generic;
20 using System.Diagnostics;
21 using System.IO;
22 using System.Text.RegularExpressions;
23 
24 namespace NShader
25 {
26 
27  public class EnumMap<T> : Dictionary<string, T>
28  {
29  public void Load(string resource)
30  {
31  Stream file = typeof(T).Assembly.GetManifestResourceStream(typeof(SiliconStudio.Paradox.VisualStudio.Resources).Namespace + ".NShader.Common." + resource);
32  TextReader textReader = new StreamReader(file);
33  string line;
34  while ((line = textReader.ReadLine()) != null )
35  {
36  int indexEqu = line.IndexOf('=');
37  if ( indexEqu > 0 )
38  {
39  string enumName = line.Substring(0, indexEqu);
40  string value = line.Substring(indexEqu + 1, line.Length - indexEqu-1).Trim();
41  string[] values = Regex.Split(value, @"[\t ]+");
42  T enumValue = (T)Enum.Parse(typeof(T), enumName);
43  foreach (string token in values)
44  {
45  if (!ContainsKey(token))
46  {
47  Add(token, enumValue);
48  } else
49  {
50  Trace.WriteLine(string.Format("Warning: token {0} for enum {1} already added for {2}", token, enumValue, this[token]));
51  }
52  }
53  }
54 
55  }
56  }
57  }
58 }
void Load(string resource)
Definition: EnumMap.cs:29