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


C# CodeDomProvider类代码示例

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


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

示例1: 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

示例2: CompileScriptFromSource

        public static Assembly CompileScriptFromSource(string source, CodeDomProvider provider, ref string errors)
        {
            StringBuilder errorLog = new StringBuilder();
            errors = "";
            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.GenerateExecutable = false;
            compilerParameters.GenerateInMemory = true;
            compilerParameters.IncludeDebugInformation = false;
            compilerParameters.ReferencedAssemblies.Add("System.dll");
            compilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            compilerParameters.ReferencedAssemblies.Add("KedrahCore.dll");
            compilerParameters.ReferencedAssemblies.Add("TibiaAPI.dll");
            compilerParameters.ReferencedAssemblies.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);
            CompilerResults results = provider.CompileAssemblyFromSource(compilerParameters, source);
            if (!results.Errors.HasErrors)
            {
                return results.CompiledAssembly;
            }
            else
            {
                foreach (CompilerError error in results.Errors)
                {
                    errorLog.AppendLine(error.ErrorText);
                }
            }

            errors = errorLog.ToString();
            return null;
        }
开发者ID:Tomaszber93,项目名称:kedrahcore,代码行数:29,代码来源:Scripter.cs

示例3: TemplateCompilationParameters

 protected TemplateCompilationParameters(RazorCodeLanguage language, CodeDomProvider codeProvider, CompilerParameters compilerParameters = null)
 {
     Language = language;
     CodeProvider = codeProvider;
     CompilerParameters = compilerParameters ?? new CompilerParameters { GenerateInMemory = true };
     AddAssemblyReference(typeof(TemplateBase));
 }
开发者ID:RazorPad,项目名称:RazorPad.Core,代码行数:7,代码来源:TemplateCompilationParameters.cs

示例4: GetGeneratorOptions

    public override CodeGeneratorOptions GetGeneratorOptions (CodeDomProvider provider) {
        CodeGeneratorOptions generatorOptions = base.GetGeneratorOptions (provider);
#if WHIDBEY
        generatorOptions.VerbatimOrder = true;
#endif
        return generatorOptions;
    }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:7,代码来源:regiondirectivetest.cs

示例5: GenerateTestFile

 private void GenerateTestFile(SpecFlowFeatureFile featureFile, CodeDomProvider codeProvider, TextWriter outputWriter)
 {
     using(var reader = new StreamReader(featureFile.GetFullPath(project)))
     {
         GenerateTestFile(featureFile, codeProvider, reader, outputWriter);
     }
 }
开发者ID:nandrew,项目名称:SpecFlow,代码行数:7,代码来源:SpecFlowGenerator.cs

示例6: Is

 public static CodeExpression Is(CodeVariableReferenceExpression var,
     CodeTypeReferenceExpression type, CodeDomProvider provider)
 {
     return new CodeSnippetExpression(
         "((" + ExpressionToString(var, provider) + ") is " +
         ExpressionToString(type, provider) + ")");
 }
开发者ID:smoothfriction,项目名称:SmoothReflections,代码行数:7,代码来源:IltoCSharpConverter.cs

示例7: BuildTree

    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu) {
        //cu.UserData["AllowLateBound"] = true;

        // GENERATES (C#):
        //  namespace Namespace1 {
        //      using System;
        //      
        //      
        //      public class Class1 {
        //          
        //          public virtual string Foo1(string format, [System.Runtime.InteropServices.OptionalAttribute()] params object[] array) {
        //              string str;
        //              str = format.Replace("{0}", array[0].ToString());
        //              str = str.Replace("{1}", array[1].ToString());
        //              str = str.Replace("{2}", array[2].ToString());
        //              return str;
        //          }
        //      }
        //  }

        CodeNamespace ns = new CodeNamespace("Namespace1");
        ns.Imports.Add(new CodeNamespaceImport("System"));
        cu.Namespaces.Add(ns);

        // Full Verification Objects
        CodeTypeDeclaration class1 = new CodeTypeDeclaration();
        class1.Name = "Class1";

        ns.Types.Add(class1);

        AddScenario ("CheckFoo1");
        CodeMemberMethod fooMethod1 = new CodeMemberMethod();
        fooMethod1.Name = "Foo1";
        fooMethod1.Attributes = MemberAttributes.Public ; 
        fooMethod1.ReturnType = new CodeTypeReference(typeof(string));

        CodeParameterDeclarationExpression parameter1 = new CodeParameterDeclarationExpression();
        parameter1.Name = "format";
        parameter1.Type = new CodeTypeReference(typeof(string));
        fooMethod1.Parameters.Add(parameter1);

        CodeParameterDeclarationExpression parameter2 = new CodeParameterDeclarationExpression();
        parameter2.Name = "array";
        parameter2.Type = new CodeTypeReference(typeof(object[]));

        if (Supports (provider, GeneratorSupport.ParameterAttributes)) {
            parameter2.CustomAttributes.Add( new CodeAttributeDeclaration("System.ParamArrayAttribute"));
            parameter2.CustomAttributes.Add( new CodeAttributeDeclaration("System.Runtime.InteropServices.OptionalAttribute"));
        }
        fooMethod1.Parameters.Add(parameter2);
        class1.Members.Add(fooMethod1);
        
        fooMethod1.Statements.Add( new CodeVariableDeclarationStatement(typeof(string), "str")); 
            
        fooMethod1.Statements.Add(CreateStatement(new CodeArgumentReferenceExpression ("format"), 0));
        fooMethod1.Statements.Add(CreateStatement(new CodeVariableReferenceExpression ("str"), 1));
        fooMethod1.Statements.Add(CreateStatement(new CodeVariableReferenceExpression ("str"), 2));
       
        fooMethod1.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("str")));
    }
开发者ID:drvink,项目名称:FSharp.Compiler.CodeDom,代码行数:60,代码来源:paramstest.cs

示例8: ContentTypeWriter

 public ContentTypeWriter(ICodeGenerationOptions options, CodeDomProvider codeDomProvider, IContentTypeCodeBuilder codeBuilder, MemberNameValidator memberNameValidator)
 {
     _options = options ?? (ICodeGenerationOptions)ComposerMigrationOptions.Default;
     _codeDomProvider = codeDomProvider;
     _codeBuilder = codeBuilder;
     _memberNameValidator = memberNameValidator;
 }
开发者ID:nordseth,项目名称:ComposerMigration,代码行数:7,代码来源:ContentTypeWriter.cs

示例9: BuildTree

    public override void BuildTree (CodeDomProvider provider, CodeCompileUnit cu) {

        if (!(provider is JScriptCodeProvider)) {
            // GENERATES (C#):
            //
            //  namespace Namespace1 {
            //      
            //      public class TEST {
            //          
            //          public static void Main() {
            //              // the following is repeated Char.MaxValue times
            //              System.Console.WriteLine(/* character value goes here */);
            //          }
            //      }
            //  }
            CodeNamespace ns = new CodeNamespace ("Namespace1");
            ns.Imports.Add (new CodeNamespaceImport ("System"));
            cu.Namespaces.Add (ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration ("TEST");
            cd.IsClass = true;
            ns.Types.Add (cd);
            CodeEntryPointMethod methodMain = new CodeEntryPointMethod ();

            for (int i = 0; i < Char.MaxValue; i+=50)
                methodMain.Statements.Add (CDHelper.ConsoleWriteLineStatement (new CodePrimitiveExpression (System.Convert.ToChar (i))));

            cd.Members.Add (methodMain);
        }
    }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:30,代码来源:unicodecharescapetest.cs

示例10: BuildTree

    public override void BuildTree (CodeDomProvider provider, CodeCompileUnit cu) {

        // GENERATES (C#):
        //
        //  namespace NSPC {
        //      
        //      public class ClassWithMethod {
        //          
        //          public int MethodName() {
        //              This is a CODE SNIPPET #*$*@;
        //              return 3;
        //          }
        //      }
        //  }
        AddScenario ("FindSnippet", "Find code snippet in the code.");
        CodeNamespace nspace = new CodeNamespace ("NSPC");
        cu.Namespaces.Add (nspace);

        CodeTypeDeclaration class1 = new CodeTypeDeclaration ("ClassWithMethod");
        class1.IsClass = true;
        nspace.Types.Add (class1);

        CodeMemberMethod cmm = new CodeMemberMethod ();
        cmm.Name = "MethodName";
        cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
        cmm.ReturnType = new CodeTypeReference (typeof (int));
        cmm.Statements.Add (new CodeExpressionStatement (new CodeSnippetExpression ("This is a CODE SNIPPET #*$*@")));
        cmm.Statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (3)));
        class1.Members.Add (cmm);
    }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:30,代码来源:codesnippettest.cs

示例11: SchemaImporter

 internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, System.Xml.Serialization.ImportContext context)
 {
     if (!schemas.Contains("http://www.w3.org/2001/XMLSchema"))
     {
         schemas.AddReference(XmlSchemas.XsdSchema);
         schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
     }
     if (!schemas.Contains("http://www.w3.org/XML/1998/namespace"))
     {
         schemas.AddReference(XmlSchemas.XmlSchema);
         schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
     }
     this.schemas = schemas;
     this.options = options;
     this.codeProvider = codeProvider;
     this.context = context;
     this.Schemas.SetCache(this.Context.Cache, this.Context.ShareTypes);
     SchemaImporterExtensionsSection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection;
     if (section != null)
     {
         this.extensions = section.SchemaImporterExtensionsInternal;
     }
     else
     {
         this.extensions = new SchemaImporterExtensionCollection();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:SchemaImporter.cs

示例12: BuildTree

    public override void BuildTree (CodeDomProvider provider, CodeCompileUnit cu) {
#if WHIDBEY
        if (!(provider is JScriptCodeProvider)) {
            cu.ReferencedAssemblies.Add("System.dll");
            cu.UserData["AllowLateBound"] = true;

            CodeNamespace ns = new CodeNamespace("Namespace1");
            ns.Imports.Add(new CodeNamespaceImport("System"));
            cu.Namespaces.Add(ns);

            AddScenario ("FindPartialClass", "Attempt to find 'PartialClass'");
            BuildClassesIntoNamespace (provider, ns, "PartialClass", ClassTypes.Class, TypeAttributes.Public);
            AddScenario ("FindSealedPartialClass", "Attempt to find 'SealedPartialClass'");
            BuildClassesIntoNamespace (provider, ns, "SealedPartialClass", ClassTypes.Class, TypeAttributes.Sealed);
            BuildClassesIntoNamespace (provider, ns, "AbstractPartialClass", ClassTypes.Class, TypeAttributes.Abstract);
            BuildClassesIntoNamespace (provider, ns, "PrivatePartialClass", ClassTypes.Class, TypeAttributes.NotPublic);

            if (Supports (provider, GeneratorSupport.DeclareValueTypes)) {
                AddScenario ("FindSealedPartialStruct", "Attempt to find 'SealedPartialStruct'");
                BuildClassesIntoNamespace (provider, ns, "SealedPartialStruct", ClassTypes.Struct, TypeAttributes.Sealed);
                BuildClassesIntoNamespace (provider, ns, "AbstractPartialStruct", ClassTypes.Struct, TypeAttributes.Abstract);
            }
        }
#endif
    }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:25,代码来源:partialclasstest.cs

示例13: Compile

		/////////////////////////////////////////////////////////////////////////////

		protected CompilerResults Compile(	CodeDomProvider codeProvider,
																				IEnumerable<string> compilerOptions,
																				IList<string> refAssemblies,
																				string assemblyName,
																				IList<string> filesIn,
																				IList<string> sourcesIn
																			)
		{
			// ******
			if( forceDebug ) {
				compilerOptions = ForceDebug( compilerOptions );
			}

	//
	// ??if want debug info then have to make sure code is passed in as a
	// file and library is on disk - currently no matter what we pass in
	// for debug we get "/debug-" in the xxx.cmdline file passed to the
	// compiler
	// 


			// ******
			using( var cb = new CodeCompileRunner(TempFilesDir, KeepTempFiles, codeProvider, compilerOptions) ) {
				var result = cb.Compile( refAssemblies, assemblyName, filesIn, sourcesIn );
				ErrorMessage = cb.ErrorMessage;
				return result;
			}
		}
开发者ID:jmclain,项目名称:Nmp,代码行数:30,代码来源:CodeCompile.cs

示例14: BuildTree

    public override void BuildTree (CodeDomProvider provider, CodeCompileUnit cu) {
        CodeNamespace ns = new CodeNamespace ("Namespace1");
        cu.Namespaces.Add (ns);

        // GENERATES (C#):
        //
        //   namespace Namespace1 {
        //      public class Class1 {
        //          public int Method1 {
        //              #line 300 "LinedStatement"
        //              return 0;
        //
        //              #line default
        //              #line hidden
        //          }
        //      }
        //   }

        CodeTypeDeclaration class1 = new CodeTypeDeclaration ("Class1");
        class1.IsClass = true;
        class1.Attributes = MemberAttributes.Public;
        ns.Types.Add (class1);

        CodeMemberMethod method1 = new CodeMemberMethod ();
        method1.ReturnType = new CodeTypeReference (typeof (int));
        method1.Name = "Method1";
        class1.Members.Add (method1);

        AddScenario ("FindLinedStatement");
        CodeMethodReturnStatement ret = new CodeMethodReturnStatement (new CodePrimitiveExpression (0));
        ret.LinePragma = new CodeLinePragma ("LinedStatement", 300);
        method1.Statements.Add (ret);
    }
开发者ID:drvink,项目名称:FSharp.Compiler.CodeDom,代码行数:33,代码来源:linepragmatest.cs

示例15: Init

 public static void Init(this IPersistentMemberInfo persistentMemberInfo, Type codeTemplateType, CodeDomProvider codeDomProvider)
 {
     persistentMemberInfo.CodeTemplateInfo.CodeTemplate =CodeTemplateBuilder.CreateDefaultTemplate(
         persistentMemberInfo is IPersistentCollectionMemberInfo
             ? TemplateType.ReadOnlyMember
             : TemplateType.ReadWriteMember, persistentMemberInfo.Session, codeTemplateType,codeDomProvider);
 }
开发者ID:cevious,项目名称:eXpand,代码行数:7,代码来源:TypeInfoExtensions.cs


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