PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/Runtime/Dreaming/Codex.cs

#
C# | 113 lines | 82 code | 9 blank | 22 comment | 2 complexity | 82dc669c1159430cfee3f435a7afc484 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.CodeDom.Compiler;
  7. namespace Refl.Dreaming
  8. {
  9. /// <summary>
  10. /// Codex Class. Used to Store Code.
  11. /// </summary>
  12. public class Codex
  13. {
  14. #region Globals
  15. internal Delegate _Del_Code;
  16. internal String _Str_Code;
  17. internal Language _Language;
  18. internal bool _isString = false;
  19. internal bool _isCompiled = false;
  20. #endregion
  21. /// <summary>
  22. /// Constructor which receives code in delegate form.
  23. /// </summary>
  24. /// <param name="code">The code delegate.</param>
  25. public Codex(Delegate code)
  26. {
  27. //Since we are receiving a delegate, we can only expect it in compiled form (IL).
  28. _Language = Language.IL;
  29. _Del_Code = code;
  30. _isString = false;
  31. }
  32. /// <summary>
  33. /// Constructor which receives code in string form.
  34. /// </summary>
  35. /// <param name="code">The code string.</param>
  36. /// <param name="language">The language in which the code was written</param>
  37. public Codex(String code, Language language = Language.ReflectiveSharp)
  38. {
  39. _Language = language;
  40. _Str_Code = code;
  41. _isString = true;
  42. }
  43. public override string ToString()
  44. {
  45. if (_isString) { return _Str_Code; }
  46. else { return _Del_Code.ToString(); }
  47. }
  48. #region 'Overloads'
  49. public static implicit operator Codex(string str)
  50. {
  51. return new Codex(str, Language.ReflectiveSharp);
  52. }
  53. public static implicit operator Codex(Delegate mi)
  54. {
  55. return new Codex(mi);
  56. }
  57. #endregion
  58. }
  59. /// <summary>
  60. /// Enum that defines the available languages in the ReflectiveCS.Dreaming namespace, that may be used in the Dream Class.
  61. /// </summary>
  62. public enum DreamLanguage
  63. {
  64. Brainfuck = 0,
  65. CPlusPlus = 1,
  66. CSharp = 2,
  67. FSharp = 3,
  68. IL = 4,
  69. IronPython = 5,
  70. IronRuby = 6,
  71. JScript = 8,
  72. ReflectiveSharp = 10,
  73. VisualBasic = 11,
  74. }
  75. /// <summary>
  76. /// Enum that defines the available languages in the ReflectiveCS.Dreaming namespace, that may be used in the Script Class.
  77. /// </summary>
  78. public enum ScriptLanguage
  79. {
  80. Brainfuck = 0,
  81. IronPython = 5,
  82. IronRuby = 6,
  83. JavaScript = 8,
  84. Lua = 9,
  85. }
  86. /// <summary>
  87. /// Enum that defines the available languages in the ReflectiveCS.Dreaming namespace.
  88. /// </summary>
  89. public enum Language
  90. {
  91. Brainfuck = 0,
  92. CPlusPlus = 1,
  93. CSharp = 2,
  94. FSharp = 3,
  95. IL = 4,
  96. IronPython = 5,
  97. IronRuby = 6,
  98. JavaScript = 7,
  99. JScript = 8,
  100. Lua = 9,
  101. ReflectiveSharp = 10,
  102. VisualBasic = 11,
  103. }
  104. }