当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.CompilerParameters类代码示例

本文整理汇总了C#中System.CodeDom.Compiler.CompilerParameters的典型用法代码示例。如果您正苦于以下问题:C# CompilerParameters类的具体用法?C# CompilerParameters怎么用?C# CompilerParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompilerParameters类属于System.CodeDom.Compiler命名空间,在下文中一共展示了CompilerParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: init

 private bool init(string generateCode, params string[] referenceAssemblies)
 {
     bool flag = false;
     result = null;
     using (CSharpCodeProvider provider = new CSharpCodeProvider())
     {
         ICodeCompiler objICodeCompiler = provider.CreateCompiler();
         CompilerParameters objCompilerParameters = new CompilerParameters();
         if (referenceAssemblies != null)
             objCompilerParameters.ReferencedAssemblies.AddRange(referenceAssemblies);
         objCompilerParameters.GenerateExecutable = false;
         objCompilerParameters.GenerateInMemory = true;
         result = objICodeCompiler.CompileAssemblyFromSource(objCompilerParameters, generateCode);
     }
     if (result != null)
     {
         if (result.Errors.Count > 0 && ErrorHandler != null)
         {
             ErrorHandler(result.Errors);
         }
         else
         {
             flag = true;
         }
     }
     return flag;
 }
开发者ID:Tony-Liang,项目名称:Common,代码行数:27,代码来源:CSharpBuilder.cs

示例2: GenerateCode

        public static System.Reflection.Assembly GenerateCode(ITextTemplatingEngineHost host, ParsedTemplate pt, 
		                                                       TemplateSettings settings, CodeCompileUnit ccu)
        {
            CompilerParameters pars = new CompilerParameters ();
            pars.GenerateExecutable = false;

            if (settings.Debug) {
                pars.GenerateInMemory = false;
                pars.IncludeDebugInformation = true;
                pars.TempFiles.KeepFiles = true;
            } else {
                pars.GenerateInMemory = true;
                pars.IncludeDebugInformation = false;
            }

            //resolve and add assembly references
            HashSet<string> assemblies = new HashSet<string> ();
            assemblies.UnionWith (settings.Assemblies);
            assemblies.UnionWith (host.StandardAssemblyReferences);
            foreach (string assem in assemblies) {
                string resolvedAssem = host.ResolveAssemblyReference (assem);
                if (!String.IsNullOrEmpty (resolvedAssem)) {
                    pars.ReferencedAssemblies.Add (resolvedAssem);
                } else {
                    pt.LogError ("Could not resolve assembly reference '" + assem + "'");
                    return null;
                }
            }
            CompilerResults results = settings.Provider.CompileAssemblyFromDom (pars, ccu);
            pt.Errors.AddRange (results.Errors);
            if (pt.Errors.HasErrors)
                return null;
            return results.CompiledAssembly;
        }
开发者ID:ferrislucas,项目名称:StatefulT4Processor,代码行数:34,代码来源:TemplatingEngine.cs

示例3: ReflectionHelper

        static ReflectionHelper()
        {
            UsingNamespaces = new List<String>();
            ClearUsings();

            // Create the C# Code Provider to compile C# Code
            IDictionary<string, string> providerOptions = new Dictionary<string, string>();
            providerOptions.Add("CompilerVersion", "v3.5");
            CodeProvider = new CSharpCodeProvider(providerOptions);
            CompilerParameters = new CompilerParameters();

            // Generate aclass library instead of an executable
            CompilerParameters.GenerateExecutable = false;

            // Specify the assembly file name to generate.
            CompilerParameters.OutputAssembly = "C:\\DummyAssembly.dll";

            // Save the assembly as a physical file.
            CompilerParameters.GenerateInMemory = false;

            // Set whether to treat all warnings as errors.
            CompilerParameters.TreatWarningsAsErrors = false;

            // Add a reference to the game and System.dll and XNA
            //CompilerParameters.ReferencedAssemblies.Add(typeof(Game).Assembly.FullName);
            ClearReferencedAsseblies();
        }
开发者ID:bartwe,项目名称:Gearset,代码行数:27,代码来源:ReflectionHelper.cs

示例4: Compile

        // Здійснює компіляцію програми, яка обчислює задану функцію
        public bool Compile(string str)
        {
            // Клас, який надає можливості компіляції:
            CodeDomProvider icc = CodeDomProvider.CreateProvider("CSharp");

            // Параметри компілятора:
            CompilerParameters cp = new CompilerParameters();
            cp.ReferencedAssemblies.Add("system.dll"); // підключаємо складання
            cp.CompilerOptions = "/t:library"; // створюємо бібліотеку
            cp.GenerateInMemory = true; // створюємо складання у пам'яті

            // Створюємо рядок, який містить вихідний код класу Func
            StringBuilder sb = new StringBuilder("");
            sb.Append("using System;\n");
            sb.Append("namespace Func{ \n");
            sb.Append("public class Func{ \n");
            sb.Append("public double MyFunc(double x){\n");
            // З функції MyFunc повертаємо вираз, отриманий у вигляді рядку:
            sb.Append("return " + str + "; \n");
            sb.Append("} \n");
            sb.Append("} \n");
            sb.Append("}\n");

            // Здійснюємо компіляцію:
            CompilerResults cr = icc.CompileAssemblyFromSource(cp, sb.ToString());
            if (cr.Errors.Count > 0)
                return false;
            assembly = cr.CompiledAssembly;
            return true;
        }
开发者ID:elluvium,项目名称:MathMethods_2,代码行数:31,代码来源:FunctionFromString.cs

示例5: UpdateSource

        public void UpdateSource()
        {
            _codeType = null;
            _codeInstance = null;
            if (Source == null)
                return;

            var provider = new CSharpCodeProvider();
            var options = new CompilerParameters { GenerateInMemory = true };
            string qn = typeof(Point3D).Assembly.Location;
            options.ReferencedAssemblies.Add("System.dll");
            options.ReferencedAssemblies.Add(qn);
            string src = template.Replace("#code#", Source);
            CompilerResults compilerResults = provider.CompileAssemblyFromSource(options, src);
            if (!compilerResults.Errors.HasErrors)
            {
                Errors = null;
                var assembly = compilerResults.CompiledAssembly;
                _codeInstance = assembly.CreateInstance("MyNamespace.MyEvaluator");
                _codeType = _codeInstance.GetType();
            }
            else
            {
                // correct line numbers
                Errors = compilerResults.Errors;
                for (int i = 0; i < Errors.Count; i++)
                    Errors[i].Line -= 17;
            }

            _w = ParameterW;
            UpdateModel();
        }
开发者ID:dermeister0,项目名称:helix-toolkit,代码行数:32,代码来源:DynamicSurface3D.cs

示例6: Compile

        public bool Compile(string src)
        {
            var param = new CompilerParameters(new string[]
            {
                "System.dll",
                "mscorlib.dll",
                "System.Data.dll",
                "System.Xml.dll",
                "System.Xml.Linq.dll",
                "lib.dll",
                "compiler.dll",
            });
            param.GenerateInMemory = true;
            param.GenerateExecutable = false;
            param.IncludeDebugInformation = false;

            _provider = new CSharpCodeProvider(
                new Dictionary<string, string>()
                {
                    { "CompilerVersion", "v4.0" },
                });
            _results = _provider.CompileAssemblyFromSource(param, src);
            if (_results.Errors.Count > 0)
            {
                foreach (CompilerError err in _results.Errors)
                {
                    if (err.IsWarning) Console.WriteLine("[Warning] {0}: [{1}] {2}", err.Line, err.ErrorNumber, err.ErrorText);
                    else Console.WriteLine("[Error] {0}: [{1}] {2}", err.Line, err.ErrorNumber, err.ErrorText);
                }
                return false;
            }

            return true;
        }
开发者ID:hal1932,项目名称:cstest,代码行数:34,代码来源:Compiler.cs

示例7: CompileCore

 Type CompileCore(IPersistentAssemblyInfo persistentAssemblyInfo, string generateCode, CompilerParameters compilerParams, System.CodeDom.Compiler.CodeDomProvider codeProvider) {
     CompilerResults compileAssemblyFromSource = null;
     Type compileCore = null;
     try {
         compileAssemblyFromSource = codeProvider.CompileAssemblyFromSource(compilerParams, generateCode);
         if (compilerParams.GenerateInMemory) {
             Assembly compiledAssembly = compileAssemblyFromSource.CompiledAssembly;
             _compiledAssemblies.Add(compiledAssembly);
             compileCore = compiledAssembly.GetTypes().Single(type => typeof(ModuleBase).IsAssignableFrom(type));
         }
     } catch (Exception e) {
         Tracing.Tracer.LogError(e);
     } finally {
         if (compileAssemblyFromSource != null) {
             SetErrors(compileAssemblyFromSource, persistentAssemblyInfo, compilerParams);
         }
         if (string.IsNullOrEmpty(persistentAssemblyInfo.CompileErrors) && compileCore != null) {
             if (!ValidateBOModel(persistentAssemblyInfo, compileCore))
                 compileCore = null;
         }
         if (Directory.Exists(StrongKeys))
             Directory.Delete(StrongKeys, true);
     }
     return compileCore;
 }
开发者ID:kamchung322,项目名称:eXpand,代码行数:25,代码来源:CompileEngine.cs

示例8: ExecuteScript

        private static object ExecuteScript(string script, ScriptExecutionOptions options)
        {
            object result = null;

            CompilerParameters cpar = new CompilerParameters();
            cpar.GenerateInMemory = true;
            cpar.ReferencedAssemblies.Add("mscorlib.dll");
            cpar.ReferencedAssemblies.Add("System.dll");
            cpar.ReferencedAssemblies.Add("System.Core.dll");
            cpar.ReferencedAssemblies.Add("System.Data.dll");
            cpar.ReferencedAssemblies.Add("System.Xml.dll");
            cpar.ReferencedAssemblies.Add(typeof(CSharpScriptingProvider).Assembly.Location);

            string code = Properties.Resources.ScriptProviderCSharpTemplate;
            code = code.Replace("{Source}", script);

            CSharpCodeProvider csp = new CSharpCodeProvider();
            CompilerResults res = csp.CompileAssemblyFromSource(cpar, code);

            if (!res.Errors.HasErrors)
            {
                MethodInfo func = res.CompiledAssembly.ExportedTypes.First().GetMethods().First();
                result = func.Invoke(null, new object[] { options });
            }

            return result;
        }
开发者ID:chrishensel,项目名称:ezNReporting,代码行数:27,代码来源:CSharpScriptingProvider.cs

示例9: MainForm

        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

             CodeCompileUnit cu = GeneraCodigo();
             CodeDomProvider dp = CodeDomProvider.CreateProvider("CSharp");
             //Imprimir el código
             StringWriter sw = new StringWriter();
             System.CodeDom.Compiler.IndentedTextWriter itw = new IndentedTextWriter(sw);
             CodeGeneratorOptions go = new CodeGeneratorOptions();
             go.BlankLinesBetweenMembers = false;
             dp.GenerateCodeFromCompileUnit(cu,sw,go);
             this.tbFuenteGenerado.Text = sw.ToString();

             //Compilar desde dom
             CompilerParameters cp = new CompilerParameters(new string[]{},"borrame.dll");
             CompilerResults cr = dp.CompileAssemblyFromDom(cp,cu);
             tbErrores.Text = "";
             foreach(CompilerError ce in cr.Errors){
             	tbErrores.Text += String.Format("{0}){1} in {2} at line {3} column {4} isWarning{5}",ce.ErrorNumber,ce.ErrorText,ce.FileName,ce.Line,ce.Column,ce.IsWarning);
             }
        }
开发者ID:IvanCruzFraguela,项目名称:EjemploGeneracionCodigo,代码行数:25,代码来源:MainForm.cs

示例10: BuildSharedAssembly

        private static CompilerResults BuildSharedAssembly(string sAssemblyName, string sFrameworkVersion, string[] hCode)
        {
            CompilerParameters hBuildParams         = new CompilerParameters();
            hBuildParams.OutputAssembly             = sAssemblyName;
            hBuildParams.GenerateExecutable         = false;
            hBuildParams.GenerateInMemory           = false;
            #if DEBUG
            hBuildParams.IncludeDebugInformation    = true;
            hBuildParams.TempFiles                  = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
            #else
            hBuildParams.IncludeDebugInformation    = false;
            hBuildParams.CompilerOptions            = "/optimize";
            #endif
            Assembly hRootAssembly = sFrameworkVersion == "v3.5" ? Assembly.Load(Assembly.GetExecutingAssembly().GetReferencedAssemblies().Where(hA => hA.Name == "Netbase.Shared").Single()) : Assembly.GetExecutingAssembly();

            foreach (AssemblyName hAssemblyName in hRootAssembly.GetReferencedAssemblies())
            {
                Assembly hLoaded = Assembly.Load(hAssemblyName);
                hBuildParams.ReferencedAssemblies.Add(hLoaded.Location);
            }

            Dictionary<string, string> hOptions = new Dictionary<string, string>();
            hOptions.Add("CompilerVersion", sFrameworkVersion);

            using (CodeDomProvider hCodeDom = CodeDomProvider.CreateProvider("CSharp", hOptions))
            {
                return hCodeDom.CompileAssemblyFromSource(hBuildParams, hCode);
            }
        }
开发者ID:Alx666,项目名称:Netbase,代码行数:29,代码来源:Program.cs

示例11: BuildServerAssembly

        private static CompilerResults BuildServerAssembly(Assembly hProtocolAssembly, string sAssemblyName, string sFrameworkVersion, string[] hCode)
        {
            CompilerParameters hBuildParams = new CompilerParameters();
            hBuildParams.OutputAssembly = sAssemblyName;
            hBuildParams.GenerateExecutable = false;
            hBuildParams.GenerateInMemory = false;
            #if DEBUG
            hBuildParams.IncludeDebugInformation = true;
            hBuildParams.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
            #else
            hBuildParams.IncludeDebugInformation    = false;
            hBuildParams.CompilerOptions            = "/optimize";
            #endif
            Assembly hExecutingAssembly = Assembly.GetExecutingAssembly();

            foreach (AssemblyName hAssemblyName in hExecutingAssembly.GetReferencedAssemblies())
            {
                hBuildParams.ReferencedAssemblies.Add(Assembly.Load(hAssemblyName).Location);
            }

            hBuildParams.ReferencedAssemblies.Add(hExecutingAssembly.Location);
            hBuildParams.ReferencedAssemblies.Add(hProtocolAssembly.Location);
            hBuildParams.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
            hBuildParams.ReferencedAssemblies.Add(typeof(Netbase.Server.ServerIOCP<>).Assembly.Location);

            Dictionary<string, string> hOptions = new Dictionary<string, string>();
            hOptions.Add("CompilerVersion", sFrameworkVersion);

            using (CodeDomProvider hCodeDom = CodeDomProvider.CreateProvider("CSharp", hOptions))
            {
                return hCodeDom.CompileAssemblyFromSource(hBuildParams, hCode);
            }
        }
开发者ID:Alx666,项目名称:Netbase,代码行数:33,代码来源:Program.cs

示例12: Compile

        public Tuple<StringCollection, Assembly> Compile(string[] dllFiles, string[] sourceFiles, string outputAssemblyPath)
        {
            var providerOptions = new Dictionary<string,
            string> { {
                    "CompilerVersion",
                    "v4.0"
                }
            };
            CodeDomProvider codeProvider = new CSharpCodeProvider(providerOptions);
            var compilerParameters = new CompilerParameters
            {
                GenerateExecutable = false,
                GenerateInMemory = true,
                IncludeDebugInformation = true
            };

            compilerParameters.ReferencedAssemblies.AddRange(dllFiles);
            compilerParameters.ReferencedAssemblies.Add("System.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Core.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Web.Services.dll");
            compilerParameters.ReferencedAssemblies.Add("System.ComponentModel.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Xml.Serialization.dll");
            var result = codeProvider.CompileAssemblyFromFile(compilerParameters, sourceFiles);
            return new Tuple<StringCollection,
            Assembly>(result.Output, result.Errors.Count > 0 ? null : result.CompiledAssembly);
        }
开发者ID:contactsamie,项目名称:FunUnit,代码行数:26,代码来源:DynaInvoke.cs

示例13: CompileSiteModels

        public void CompileSiteModels()
        {
            DirectoryInfo di = new DirectoryInfo(SysPath.SiteModelsDirectory);
            FileInfo[] fiar = di.GetFiles("*.cs");
            String[] fisar = new String[fiar.Length];

            for (int i = 0; i < fiar.Length; i++)
            {
                fisar[i] = fiar[i].FullName;
            }

            CompilerParameters parameters = new CompilerParameters(new String[] { "System.dll", "NStag.dll", "nhibernate.dll" });
            parameters.GenerateExecutable = false;
            parameters.GenerateInMemory = true;
            parameters.OutputAssembly = this.DomainName;
            parameters.CompilerOptions = String.Concat("/lib:", SysPath.GetLibDirectory());

            CSharpCodeProvider cprovider = new CSharpCodeProvider();
            CompilerResults results = cprovider.CompileAssemblyFromFile(parameters, cspath);

            if (results.Errors.HasErrors)
            {
                throw new Exception(results.Errors[0].ErrorText);
            }
        }
开发者ID:dancecoder,项目名称:NStag-Web-Framework,代码行数:25,代码来源:NHibernateModelCompiller.cs

示例14: Compile

        public object Compile(System.IO.Stream Content, List<string> references)
        {
            CodeDomProvider cc = CodeDomProvider.CreateProvider("CSharp");
            CompilerParameters cp = new CompilerParameters();
            cp.OutputAssembly = Environment.CurrentDirectory + "\\Output_csharp.dll";
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Core.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");
            cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll");

            foreach (string assembly in references)
            {
                cp.ReferencedAssemblies.Add(assembly);
            }

            cp.WarningLevel = 3;

            cp.CompilerOptions = "/target:library /optimize";
            cp.GenerateExecutable = false;
            cp.GenerateInMemory = false; //TODO check this setting

            System.IO.StreamReader sr = new System.IO.StreamReader(Content);

            CompilerResults cr = cc.CompileAssemblyFromSource(cp, sr.ReadToEnd());

            return cr;
        }
开发者ID:rdpeake,项目名称:CodeRunners,代码行数:28,代码来源:CSharpCompiler.cs

示例15: Compiles

 /// <summary>
 /// Verifies that <paramref name="source"/> compiles using the provided compiler.
 /// </summary>
 /// <param name="compiler">Compiler instance</param>
 /// <param name="source">Source code to compile</param>
 public static CompilerResults Compiles(CodeDomProvider provider, Stream source)
 {
     Assert.IsNotNull(provider);
     Assert.IsNotNull(source);
     CompilerParameters ps = new CompilerParameters();
     return Compiles(provider, ps, source);
 }
开发者ID:sayedjalilhassan,项目名称:LearningPlatform,代码行数:12,代码来源:CompilerAssert.cs


注:本文中的System.CodeDom.Compiler.CompilerParameters类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。