/// <summary>
 /// Get a ILanguageHelper from ESupportedLanguage enum.
 /// </summary>
 /// <param name="language">supported language</param>
 /// <returns>ILanguageHelper implementation</returns>
 public static ILanguageHelper GetLanguageHelper(ESupportedLanguage language)
 {
     switch (language)
     {
         case ESupportedLanguage.CSharp: return new CSharpHelper();
         case ESupportedLanguage.VisualBasic: return new VisualBasicHelper(); 
         default: throw new System.NotSupportedException("this language is not supported");
     }
 }
        /// <summary>
        /// Get a ILanguageHelper from ESupportedLanguage enum.
        /// </summary>
        /// <param name="language">supported language</param>
        /// <returns>ILanguageHelper implementation</returns>
        public static ILanguageHelper GetLanguageHelper(ESupportedLanguage language)
        {
            switch (language)
            {
            case ESupportedLanguage.CSharp: return(new CSharpHelper());

            case ESupportedLanguage.VisualBasic: return(new VisualBasicHelper());

            default: throw new System.NotSupportedException("this language is not supported");
            }
        }
예제 #3
0
        /// <summary>
        /// Compile source code
        /// </summary>
        /// <param name="code">full source code to compile</param>
        /// <param name="references">assembly references</param>
        /// <param name="language">target language</param>
        /// <param name="compilerVersion">compiler version</param>
        public void Compile(string code, string[] references, ESupportedLanguage language, String compilerVersion)
        {
            var properties = new Dictionary <string, string> {
                { CompilerVersion, compilerVersion }
            };
            CodeDomProvider provider;

            switch (language)
            {
            case ESupportedLanguage.CSharp:
                provider = new CSharpCodeProvider(properties);
                break;

            case ESupportedLanguage.VisualBasic:
                provider = new VBCodeProvider(properties);
                break;

            default:
                throw new ArgumentException();
            }

            var parameters = new CompilerParameters
            {
                GenerateExecutable      = false,
                GenerateInMemory        = false,
                IncludeDebugInformation = false
            };

            parameters.ReferencedAssemblies.AddRange(references);

            if (language == ESupportedLanguage.CSharp)
            {
                parameters.CompilerOptions = "/unsafe";
            }

            var results = provider.CompileAssemblyFromSource(parameters, code);

            AssemblyLocation = null;
            Errors           = results.Errors;

            if (!results.Errors.HasErrors)
            {
                AssemblyLocation = results.CompiledAssembly.Location;
            }
        }
예제 #4
0
        /// <summary>
        /// Compile source code
        /// </summary>
        /// <param name="code">full source code to compile</param>
        /// <param name="references">assembly references</param>
        /// <param name="language">target language</param>
        /// <param name="compilerVersion">compiler version</param>
        public void Compile(string code, string[] references, ESupportedLanguage language, String compilerVersion)
        {
            var properties = new Dictionary<string, string> {{CompilerVersion, compilerVersion}};
            CodeDomProvider provider;

            switch (language)
            {
                case ESupportedLanguage.CSharp:
                    provider = new CSharpCodeProvider(properties);
                    break;
                case ESupportedLanguage.VisualBasic:
                    provider = new VBCodeProvider(properties);
                    break;
                default:
                    throw new ArgumentException();
            }

            var parameters = new CompilerParameters
                                 {
                                     GenerateExecutable = false,
                                     GenerateInMemory = false,
                                     IncludeDebugInformation = false
                                 };

            parameters.ReferencedAssemblies.AddRange(references);

            if (language == ESupportedLanguage.CSharp)
            {
                parameters.CompilerOptions = "/unsafe";
            }

            CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);
            _assemblyLocation = null;
            _errors = results.Errors;

            if (!results.Errors.HasErrors)
            {
                _assemblyLocation = results.CompiledAssembly.Location;
            }
        }