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


C# CodeDomProvider.CreateGenerator方法代码示例

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


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

示例1: Generate

		public static string Generate (string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider)
		{
			var dataSet = new DataSet ();
			dataSet.ReadXmlSchema (inputFileContent);
			T.Generate (dataSet, mainNamespace, codeProvider.CreateGenerator ());
			return null;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:TypedDataSetGenerator.cs

示例2: Supports

        protected bool Supports (CodeDomProvider provider, GeneratorSupport support) {
#if WHIDBEY
            return provider.Supports (support);
#else
            return (provider.CreateGenerator ()).Supports (support);
#endif
        }
开发者ID:modulexcite,项目名称:powerpack-archive,代码行数:7,代码来源:CodeDomTest.cs

示例3: GenerateTypedDataSet

 internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeNamespace codeNamespace, StringCollection references, CodeDomProvider codeProvider)
 {
     if (element == null)
     {
         return null;
     }
     if (this.importedTypes[element.SchemaType] != null)
     {
         return (string) this.importedTypes[element.SchemaType];
     }
     IList list = schemas.GetSchemas(element.QualifiedName.Namespace);
     if (list.Count != 1)
     {
         return null;
     }
     XmlSchema schema = list[0] as XmlSchema;
     if (schema == null)
     {
         return null;
     }
     DataSet dataSet = new DataSet();
     using (MemoryStream stream = new MemoryStream())
     {
         schema.Write(stream);
         stream.Position = 0L;
         dataSet.ReadXmlSchema(stream);
     }
     string name = new TypedDataSetGenerator().GenerateCode(dataSet, codeNamespace, codeProvider.CreateGenerator()).Name;
     this.importedTypes.Add(element.SchemaType, name);
     references.Add("System.Data.dll");
     return name;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:DataSetSchemaImporterExtension.cs

示例4: InitBase

		public void InitBase()
		{
			provider = new CSharpCodeProvider ();
			generator = provider.CreateGenerator ();
			options = new CodeGeneratorOptions ();
			writer = new StringWriter ();

			writer.NewLine = "\n";
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:CodeGeneratorTestBase.cs

示例5: ToCode

		public static string ToCode(CodeCompileUnit compileunit, CodeDomProvider provider)
		{

			StringBuilder sb = new StringBuilder() ;
			StringWriter sw = new StringWriter(sb);
			IndentedTextWriter tw = new IndentedTextWriter(sw, "    ");

			ICodeGenerator gen = provider.CreateGenerator(tw);

			gen.GenerateCodeFromCompileUnit(compileunit, tw, 
				new CodeGeneratorOptions());

			string code = sb.ToString();

			return code;
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:16,代码来源:CodeDomGenerator.cs

示例6: GenerateProjectCode

        public static void GenerateProjectCode(string file, CodeDomProvider provider, GenerationOptions options, ProjectBackend[] projects)
        {
            CodeGenerationResult res = GenerateProjectCode (options, projects);

            ICodeGenerator gen = provider.CreateGenerator ();
            string basePath = Path.GetDirectoryName (file);

            foreach (SteticCompilationUnit unit in res.Units) {
                string fname;
                if (unit.Name.Length == 0)
                    fname = file;
                else
                    fname = Path.Combine (basePath, unit.Name);
                StreamWriter fileStream = new StreamWriter (fname);
                try {
                    gen.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
                } finally {
                    fileStream.Close ();
                }
            }
        }
开发者ID:mono,项目名称:stetic,代码行数:21,代码来源:CodeGenerator.cs

示例7: GenerateTestCase

		private void GenerateTestCase(CodeDomProvider provider, string extension, string ns, string name, string area, 
			string[] actions, TextWriter output)
		{
			CodeNamespace nsunit = GenerateControllerTestCode(ns, name, area, actions);

			FileInfo controllerFile = new FileInfo( 
				Path.Combine(testsDir.FullName, name + "Tests" + extension) );

			if (!controllerFile.Exists)
			{
				using (StreamWriter sw = new StreamWriter(controllerFile.FullName, false, Encoding.Default))
				{
					CodeGeneratorOptions opts = new CodeGeneratorOptions();
					opts.BracingStyle = "C";
#if DOTNET2
					provider.GenerateCodeFromNamespace(nsunit, sw, opts);
#else
					provider.CreateGenerator().GenerateCodeFromNamespace(nsunit, sw, opts);
#endif
				}
			}
			else
			{
				output.WriteLine("Skipping {0} as the files exists", controllerFile.FullName);
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:26,代码来源:ControllerGenerator.cs

示例8: GenerateTypedDataSet

        internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeNamespace codeNamespace, StringCollection references, CodeDomProvider codeProvider) {
            if (element == null)
                return null;

            if (importedTypes[element.SchemaType] != null)
                return (string)importedTypes[element.SchemaType];

            IList values = schemas.GetSchemas(element.QualifiedName.Namespace);
            if (values.Count != 1) {
                return null;
            }
            XmlSchema schema = values[0] as XmlSchema;
            if (schema == null)
                return null;

            DataSet ds = new DataSet();

            // 
            using (MemoryStream stream = new MemoryStream()) {
                schema.Write(stream);
                stream.Position = 0;
                ds.ReadXmlSchema(stream);
            }

#pragma warning disable 618 // ignore obsolete warning about TypedDataSetGenerator
            CodeTypeDeclaration dsClass = new TypedDataSetGenerator().GenerateCode(ds, codeNamespace, codeProvider.CreateGenerator());
#pragma warning restore 618
            string typeName = dsClass.Name;
            importedTypes.Add(element.SchemaType, typeName);
            references.Add("System.Data.dll");
            return typeName;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:32,代码来源:DataSet.cs

示例9: ToCodeFile

        public String ToCodeFile(CodeCompileUnit compileunit, CodeDomProvider provider, string fileName)
        {
            #if NET2

            String sourceFile;
            if (provider.FileExtension[0] == '.')
                sourceFile = fileName + provider.FileExtension;
            else
                sourceFile = fileName + "." + provider.FileExtension;

            IndentedTextWriter tw = new IndentedTextWriter(
                new StreamWriter(sourceFile, false), "    ");

            provider.GenerateCodeFromCompileUnit(compileunit, tw,
                new CodeGeneratorOptions());

            tw.Close();

            return sourceFile;
            #else
            ICodeGenerator gen = provider.CreateGenerator();

            String sourceFile;
            if (provider.FileExtension[0] == '.')
                sourceFile = fileName + provider.FileExtension;
            else
                sourceFile = fileName + "." + provider.FileExtension;

            IndentedTextWriter tw = new IndentedTextWriter(
                new StreamWriter(sourceFile, false), "    ");

            gen.GenerateCodeFromCompileUnit(compileunit, tw,
                new CodeGeneratorOptions());

            tw.Close();

            return sourceFile;
            #endif
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:39,代码来源:ModelToCodeTransformer.cs

示例10: GenerateProjectCode

        public CodeGenerationResult GenerateProjectCode(string file, string namespaceName, CodeDomProvider provider, GenerationOptions options, params Project[] projects)
        {
            ArrayList files = new ArrayList ();
            CodeGenerationResult res = GenerateProjectCode (options, projects);

            ICodeGenerator gen = provider.CreateGenerator ();
            string basePath = Path.GetDirectoryName (file);
            string ext = Path.GetExtension (file);

            foreach (SteticCompilationUnit unit in res.Units) {
                string fname;
                if (unit.Name.Length == 0)
                    fname = file;
                else
                    fname = Path.Combine (basePath, unit.Name) + ext;
                files.Add (fname);
                unit.Name = fname;
                StreamWriter fileStream = new StreamWriter (fname);
                try {
                    gen.GenerateCodeFromCompileUnit (unit, fileStream, new CodeGeneratorOptions ());
                } finally {
                    fileStream.Close ();
                }
            }
            return res;
        }
开发者ID:mono,项目名称:stetic,代码行数:26,代码来源:Application.cs

示例11: InitBase

		public void InitBase()
		{
			provider = new CSharpCodeProvider ();
			generator = provider.CreateGenerator ();
			options = new CodeGeneratorOptions ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:6,代码来源:CodeGeneratorTestBase.cs

示例12: WriteClassFile

		private void WriteClassFile(Project project, String name, CodeNamespace ns, CodeDomProvider provider)
		{
			String filename =  String.Format("{0}.{1}", name, provider.FileExtension);

			FileInfo fileInfo = new FileInfo( Path.Combine(project.LastOutDir, filename) );

			if (fileInfo.Exists && !project.OverwriteFiles)
			{
				Log( String.Format("Skipping {0} as it already exists", filename) );
			}
			else
			{
				Log( String.Format("Writing {0}...", filename) );

				try
				{
					using(FileStream stream = new FileStream(fileInfo.FullName, FileMode.Create, FileAccess.Write))
					{
						StreamWriter writer = new StreamWriter(stream);
						CodeGeneratorOptions opts = new CodeGeneratorOptions();
						opts.BracingStyle = "C";
						opts.BlankLinesBetweenMembers = true;
						provider.CreateGenerator().GenerateCodeFromNamespace(ns, writer, opts);
						writer.Flush();
						writer.Close();
					}
				}
				catch(Exception ex)
				{
					Log( String.Format("Error Writing {0} []", filename, ex.Message) );
				}
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:33,代码来源:ProjectGenerator.cs

示例13: CreateCodeGenerator

        private void CreateCodeGenerator(out ICodeGenerator codeGen, out string fileExtension)
        {
            Language language1 = WsdlProperties.Language;
            switch (language1)
            {
                case Language.CS:
                    codeProvider = new CSharpCodeProvider();
                    break;

                case Language.VB:
                    codeProvider = new VBCodeProvider();
                    break;

                default:
                    {
                        if (language1 != Language.Custom)
                        {
                            throw new Exception("Unknown language");
                        }
                        Type type1 = Type.GetType(WsdlProperties.CustomCodeDomProvider);
                        if (type1 == null)
                        {
                            throw new TypeLoadException("Type '" + WsdlProperties.CustomCodeDomProvider +
                                                        "' is not found");
                        }
                        codeProvider = (CodeDomProvider) Activator.CreateInstance(type1);
                        break;
                    }
            }
            if (codeProvider != null)
            {
                codeGen = codeProvider.CreateGenerator();
                fileExtension = codeProvider.FileExtension;
                if (fileExtension == null)
                {
                    fileExtension = string.Empty;
                }
                else if ((fileExtension.Length > 0) && (fileExtension[0] != '.'))
                {
                    fileExtension = "." + fileExtension;
                }
            }
            else
            {
                fileExtension = ".src";
                codeGen = null;
            }
        }
开发者ID:irdetocustomercentral,项目名称:WebServiceStudio,代码行数:48,代码来源:Wsdl.cs

示例14: Run

 public static string Run(CodeWizard codeWizard, IServiceProvider serviceProvider, CodeDomProvider codeDomProvider, QueryBuilderType type)
 {
     IUIService service = (IUIService) serviceProvider.GetService(typeof(IUIService));
     IDatabaseManager manager = (IDatabaseManager) serviceProvider.GetService(typeof(IDatabaseManager));
     if (codeDomProvider != null)
     {
         ICodeGenerator generator = codeDomProvider.CreateGenerator();
         if (generator != null)
         {
             QueryBuilder form = new QueryBuilder(codeWizard, type);
             if (service.ShowDialog(form) == DialogResult.OK)
             {
                 StringWriter w = new StringWriter();
                 CodeGeneratorOptions o = new CodeGeneratorOptions();
                 CodeMemberMethod method = new CodeMemberMethod();
                 method.Name = form.MethodName;
                 IDictionary dictionary = new HybridDictionary(true);
                 foreach (QueryParameter parameter in form.Parameters)
                 {
                     string variableNameFromParameterName = GetVariableNameFromParameterName(parameter.Name);
                     if (dictionary[variableNameFromParameterName] == null)
                     {
                         System.Type typeFromDbType = QueryParameter.GetTypeFromDbType(parameter.Type);
                         method.Parameters.Add(new CodeParameterDeclarationExpression(typeFromDbType, variableNameFromParameterName));
                         dictionary[variableNameFromParameterName] = string.Empty;
                     }
                 }
                 method.ReturnType = new CodeTypeReference(form.ReturnType);
                 method.Attributes = MemberAttributes.Final;
                 method.Statements.AddRange(BuildConnection((IDataProviderDatabase) form.Database, ((IDataProviderDatabase) form.Database).ConnectionString));
                 method.Statements.Add(new CodeSnippetStatement(string.Empty));
                 method.Statements.Add(BuildQueryString(form.Query));
                 method.Statements.AddRange(BuildCommand((IDataProviderDatabase) form.Database));
                 method.Statements.Add(new CodeSnippetStatement(string.Empty));
                 int num = 0;
                 dictionary = new HybridDictionary(true);
                 foreach (QueryParameter parameter2 in form.Parameters)
                 {
                     string str2 = GetVariableNameFromParameterName(parameter2.Name);
                     if (dictionary[str2] == null)
                     {
                         method.Statements.AddRange(BuildDbParameterAssignment((IDataProviderDatabase) form.Database, parameter2.Name, parameter2.Type, codeDomProvider));
                         num++;
                         dictionary[str2] = string.Empty;
                     }
                 }
                 if (num > 0)
                 {
                     method.Statements.Add(new CodeSnippetStatement(string.Empty));
                 }
                 if (type == QueryBuilderType.Select)
                 {
                     if (form.ReturnType == typeof(IDataReader))
                     {
                         method.Statements.AddRange(BuildSelectReturnDataReader());
                     }
                     else
                     {
                         method.Statements.AddRange(BuildSelectReturnDataSet((IDataProviderDatabase) form.Database));
                     }
                 }
                 else
                 {
                     method.Statements.AddRange(BuildExecuteNonQuery());
                 }
                 CodeTypeDeclaration e = new CodeTypeDeclaration("TempType");
                 e.Members.Add(method);
                 generator.GenerateCodeFromType(e, w, o);
                 string s = w.ToString();
                 w = new StringWriter();
                 CodeTypeDeclaration declaration2 = new CodeTypeDeclaration("TempType");
                 generator.GenerateCodeFromType(declaration2, w, o);
                 string str4 = w.ToString();
                 w = new StringWriter();
                 StringReader reader = new StringReader(s);
                 StringReader reader2 = new StringReader(str4);
                 string str5 = reader.ReadLine();
                 string str6 = reader2.ReadLine();
                 while (str5 != null)
                 {
                     if (str5 != str6)
                     {
                         w.WriteLine(str5);
                     }
                     else
                     {
                         str6 = reader2.ReadLine();
                     }
                     str5 = reader.ReadLine();
                 }
                 return w.ToString();
             }
         }
     }
     return string.Empty;
 }
开发者ID:ikvm,项目名称:webmatrix,代码行数:96,代码来源:SqlCodeWizard.cs

示例15: CompilerInfo

 public CompilerInfo(CodeDomProvider provider)
 {
     Compiler = provider.CreateCompiler();
     CodeGen = provider.CreateGenerator();
 }
开发者ID:smaclell,项目名称:NAnt,代码行数:5,代码来源:ScriptTask.cs


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