Пример #1
0
        /// <summary> Constructor. </summary>
        /// <param name="processingView"> The view for the controller. </param>
        public ProcessingController(IProcessingView processingView)
        {
            _processingView = processingView;
            _processingView.ExpressionChanged += HandleExpressionChanged;
            _processingView.ExampleChanged    += HandleExampleChanged;

            _provider = new CSharpProvider();
        }
Пример #2
0
 internal AssemblyService(CSharpProvider provider)
 {
     this.Provider = provider;
 }
Пример #3
0
        public static Assembly MakeAssembly(string dllFileName, string dirCSharpCode, string[] fileNames)
        {
            try
            {
                string errorMessage = String.Empty;

                CSharpProvider = CodeDomProvider.CreateProvider("CSharp");

                CompilerParameters compilerParameters = new CompilerParameters()
                {
                    GenerateExecutable = false,
                    GenerateInMemory   = false,
                    //https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/compiler-options/listed-alphabetically
                    //CompilerOptions = string.Format("-nowarn:CS2005 -recurse:{0}", dirCSharpCode),
                    //TreatWarningsAsErrors = false,
                    //IncludeDebugInformation = false,
                    OutputAssembly = string.Format("{0}\\{1}.dll", dirCSharpCode, dllFileName)
                };

                //указываем системные сборки для компилятора

                //Assembly.GetEntryAssembly();
                //compilerParameters.ReferencedAssemblies.Add("EntityFramework.dll");
                //Функция GetAssemblyLocation вызывает ошибку CS2005 при повторном запуске программы!
                //string[] dllFiles = GetAssemblyLocation(new string[] {
                //        "System.dll",
                //        "System.ComponentModel.DataAnnotations.dll",
                //        "System.Data.dll",
                //        "System.Core.dll",
                //        "EntityFramework.dll"
                //});
                //string[] dllFiles = GetAssemblyLocation(new string[] {
                //        "System.dll",
                //        "System.ComponentModel.DataAnnotations.dll",
                //        "System.Data.dll",
                //});
                string[] dllFiles = new string[] {
                    "System.dll",
                    "System.ComponentModel.DataAnnotations.dll",
                    "System.Data.dll",
                    "System.Core.dll"
                };
                compilerParameters.ReferencedAssemblies.AddRange(dllFiles);

                compilerResults = CSharpProvider.CompileAssemblyFromFile(compilerParameters, fileNames);

                if (compilerResults.Errors.HasErrors)
                {
                    errorMessage = compilerResults.Errors.Count.ToString() + " Errors C# building:";
                    foreach (CompilerError ce in compilerResults.Errors)
                    {
                        errorMessage += Environment.NewLine + "Line: " + ce.ToString();
                    }
                    throw new ApplicationException(errorMessage);
                }
                return(compilerResults.CompiledAssembly);
                //return compilerResults.PathToAssembly;
            }
            catch (Exception ex)
            {
                throw new Exception("Error while trying to build generated code.", ex);
            }
        }
Пример #4
0
 public void Setup()
 {
     _provider = new CSharpProvider();
 }
Пример #5
0
 public ExpressionService(CSharpProvider provider)
 {
     this.Provider = provider;
 }