Kinetica   C#   API  Version 7.2.3.0
CodeGenUtil.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 using System.CodeDom;
23 
24 namespace Avro
25 {
29  public sealed class CodeGenUtil
30  {
31  private static readonly CodeGenUtil instance = new CodeGenUtil();
32  public static CodeGenUtil Instance { get { return instance; } }
33 
34  public CodeNamespaceImport[] NamespaceImports { get; private set; }
35  public CodeCommentStatement FileComment { get; private set; }
36  public HashSet<string> ReservedKeywords { get; private set; }
37  private const char At = '@';
38  private const char Dot = '.';
39  public const string Object = "System.Object";
40 
41  private CodeGenUtil()
42  {
43  NamespaceImports = new CodeNamespaceImport[] {
44  new CodeNamespaceImport("System"),
45  new CodeNamespaceImport("System.Collections.Generic"),
46  new CodeNamespaceImport("System.Text"),
47  new CodeNamespaceImport("Avro"),
48  new CodeNamespaceImport("Avro.Specific") };
49 
50  FileComment = new CodeCommentStatement(
51 @"------------------------------------------------------------------------------
52  <auto-generated>
53  Generated by " + System.AppDomain.CurrentDomain.FriendlyName + ", version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + @"
54  Changes to this file may cause incorrect behavior and will be lost if code
55  is regenerated
56  </auto-generated>
57  ------------------------------------------------------------------------------");
58 
59  // Visual Studio 2010 http://msdn.microsoft.com/en-us/library/x53a06bb.aspx
60  ReservedKeywords = new HashSet<string>() {
61  "abstract","as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class",
62  "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event",
63  "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
64  "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new",
65  "null", "object", "operator", "out", "override", "params", "private", "protected", "public",
66  "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static",
67  "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong",
68  "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "value", "partial" };
69  }
70 
76  public string Mangle(string name)
77  {
78  var builder = new StringBuilder();
79  string[] names = name.Split(Dot);
80  for (int i = 0; i < names.Length; ++i)
81  {
82  if (ReservedKeywords.Contains(names[i]))
83  builder.Append(At);
84  builder.Append(names[i]);
85  builder.Append(Dot);
86  }
87  builder.Remove(builder.Length - 1, 1);
88  return builder.ToString();
89  }
90 
96  public string UnMangle(string name)
97  {
98  var builder = new StringBuilder(name.Length);
99  for (int i = 0; i < name.Length; ++i)
100  if (name[i] != At)
101  builder.Append(name[i]);
102  return builder.ToString();
103  }
104  }
105 }
CodeNamespaceImport [] NamespaceImports
Definition: CodeGenUtil.cs:34
A singleton class containing data used by codegen
Definition: CodeGenUtil.cs:29
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
CodeCommentStatement FileComment
Definition: CodeGenUtil.cs:35
string UnMangle(string name)
Remove all the @
Definition: CodeGenUtil.cs:96
static CodeGenUtil Instance
Definition: CodeGenUtil.cs:32
const string Object
Definition: CodeGenUtil.cs:39
HashSet< string > ReservedKeywords
Definition: CodeGenUtil.cs:36
string Mangle(string name)
Append @ to all reserved keywords that appear on the given name
Definition: CodeGenUtil.cs:76