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


C# ICodeGenerator.GenerateCodeFromCompileUnit方法代码示例

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


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

示例1: CreateCode

        public static string CreateCode(
            Type proxyType, 
            ICodeGenerator generator,
            XmlRpcProxyCodeGenOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(
                    "options",
                    "The options parameter cannot be null");
            }

            CodeCompileUnit ccu = CreateCodeCompileUnit(proxyType, options);

            var cgo = new CodeGeneratorOptions();
            cgo.BlankLinesBetweenMembers = true;
            cgo.BracingStyle = "C";

            using (var sw = new StringWriter(CultureInfo.InvariantCulture))
            {
                generator.GenerateCodeFromCompileUnit(ccu, sw, cgo);
                return sw.ToString();
            }
        }
开发者ID:magicmonty,项目名称:xmlrpcnet,代码行数:24,代码来源:XmlRpcProxyCodeGen.cs

示例2: ImportSchemasAsClasses

        void ImportSchemasAsClasses(
            string outputdir,
            ICodeGenerator codeGen,
            string fileExtension,
            IList fileNames, 
            string ns, 
            string uri, 
            IList elements) {

            XmlSchemas schemasToCompile = new XmlSchemas();
            XmlSchemas userSchemas = new XmlSchemas();
            string outputSchemaName = "";
            // Create parent schema
            XmlSchema parent = new XmlSchema();
            foreach (string fileName in fileNames) {
                schemasToCompile.Add(ReadSchema(fileName, false));
                userSchemas.Add(ReadSchema(fileName, true));
                outputSchemaName += Path.ChangeExtension(fileName,"").Replace('.','_');
            }

            Hashtable includeSchemas = new Hashtable();
            foreach (XmlSchema schema in schemasToCompile) {
                CollectIncludes(schema, includeSchemas, false);
            }
            Compile(schemasToCompile);

            includeSchemas = new Hashtable();
            foreach (XmlSchema schema in userSchemas) {
                CollectIncludes(schema, includeSchemas, true);
            }

            try {
                outputSchemaName = outputSchemaName.Substring(0, outputSchemaName.Length - 1);
                XmlSchemaImporter schemaImporter = new XmlSchemaImporter(userSchemas);
                CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
                CodeNamespace codeNamespace = new CodeNamespace(ns);
                codeCompileUnit.Namespaces.Add(codeNamespace);
                GenerateVersionComment(codeNamespace);
                XmlCodeExporter codeExporter = new XmlCodeExporter(codeNamespace, codeCompileUnit);
                AddImports(codeNamespace, GetNamespacesForTypes(new Type[] { typeof(XmlAttributeAttribute) }));

                for (int i = 0; i < userSchemas.Count; i++) {
                    XmlSchema schema = userSchemas[i];
                    for (int j = 0; j < schema.Items.Count; j++) {
                        object item = schema.Items[j];
                        if (item is XmlSchemaElement) {
                            XmlSchemaElement element = (XmlSchemaElement)item;
                            if (!element.IsAbstract) {

                                if (uri.Length == 0 ||
                                    schema.TargetNamespace == uri) {

                                    bool found;
                                    if (elements.Count == 0) {
                                        found = true;
                                    }
                                    else {
                                        found = false;
                                        foreach (string e in elements) {
                                            if (e == element.Name) {
                                                found = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (found) {
                                        XmlTypeMapping xmlTypeMapping = schemaImporter.ImportTypeMapping(new XmlQualifiedName(element.Name, schema.TargetNamespace));
                                        codeExporter.ExportTypeMapping(xmlTypeMapping);
                                    }
                                }
                            }
                        }
                    }
                }

                CodeTypeDeclarationCollection classes = codeNamespace.Types;
                if (classes == null || classes.Count == 0) {
                    Console.WriteLine(Res.GetString(Res.NoClassesGenerated));
                }
                else {
                    TextWriter writer = CreateOutputWriter(outputdir, outputSchemaName, fileExtension);
                    codeGen.GenerateCodeFromCompileUnit(codeCompileUnit, writer, null);
                    writer.Close();
                }
            }
            catch (Exception e) {
                throw new InvalidOperationException(Res.GetString(Res.ErrGenerateClassesForSchema, outputSchemaName), e);
            }
        }
开发者ID:ArildF,项目名称:masters,代码行数:89,代码来源:xsd.cs

示例3: SaveCompileUnit

 private static void SaveCompileUnit(ICodeGenerator codegen, CodeCompileUnit cu, string fileName)
 {
     try
     {
         try
         {
             if (File.Exists(fileName))
             {
                 File.Delete(fileName);
             }
         }
         catch
         {
         }
         FileStream stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
         StreamWriter w = new StreamWriter(stream, new UTF8Encoding(false));
         codegen.GenerateCodeFromCompileUnit(cu, w, null);
         w.Flush();
         w.Close();
         stream.Close();
         GeneratedSources.Add(fileName);
     }
     catch (Exception)
     {
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:AxWrapperGen.cs

示例4: Generate

 public string Generate(ICodeGenerator codeGen)
 {
     StringWriter writer1 = new StringWriter();
     codeGen.GenerateCodeFromCompileUnit(compileUnit, writer1, null);
     return writer1.ToString();
 }
开发者ID:irdetocustomercentral,项目名称:WebServiceStudio,代码行数:6,代码来源:Script.cs

示例5: Generate

 public string Generate(ICodeGenerator codeGen)
 {
     StringWriter w = new StringWriter();
     codeGen.GenerateCodeFromCompileUnit(this.compileUnit, w, null);
     return w.ToString();
 }
开发者ID:zerostone,项目名称:webservicestudio,代码行数:6,代码来源:Script.cs

示例6: GenerateCode

 private void GenerateCode(ServiceDescriptionCollection sources, XmlSchemas schemas, string uriToWSDL,
                           ICodeGenerator codeGen, string fileExtension)
 {
     proxyCode = " <ERROR> ";
     StringWriter writer1 = null;
     compileUnit = new CodeCompileUnit();
     ServiceDescriptionImporter importer1 = new ServiceDescriptionImporter();
     importer1.Schemas.Add(schemas);
     foreach (ServiceDescription description1 in sources)
     {
         importer1.AddServiceDescription(description1, "", "");
     }
     importer1.Style = ServiceDescriptionImportStyle.Client;
     Protocol protocol1 = WsdlProperties.Protocol;
     importer1.ProtocolName = WsdlProperties.Protocol.ToString();
     CodeNamespace namespace1 = new CodeNamespace(proxyNamespace);
     compileUnit.Namespaces.Add(namespace1);
     ServiceDescriptionImportWarnings warnings1 = importer1.Import(namespace1, compileUnit);
     try
     {
         try
         {
             writer1 = new StringWriter();
         }
         catch
         {
             throw;
         }
         MemoryStream stream1 = null;
         if (schemas.Count > 0)
         {
             compileUnit.ReferencedAssemblies.Add("System.Data.dll");
             foreach (XmlSchema schema1 in schemas)
             {
                 string text1 = null;
                 try
                 {
                     text1 = schema1.TargetNamespace;
                     if (XmlSchemas.IsDataSet(schema1))
                     {
                         if (stream1 == null)
                         {
                             stream1 = new MemoryStream();
                         }
                         stream1.Position = 0;
                         stream1.SetLength((long) 0);
                         schema1.Write(stream1);
                         stream1.Position = 0;
                         DataSet set1 = new DataSet();
                         set1.ReadXmlSchema(stream1);
                         TypedDataSetGenerator.Generate(set1, namespace1, codeGen);
                     }
                     continue;
                 }
                 catch
                 {
                     throw;
                 }
             }
         }
         try
         {
             GenerateVersionComment(compileUnit.Namespaces[0]);
             ChangeBaseType(compileUnit);
             codeGen.GenerateCodeFromCompileUnit(compileUnit, writer1, null);
         }
         catch (Exception exception1)
         {
             if (writer1 != null)
             {
                 writer1.Write("Exception in generating code");
                 writer1.Write(exception1.Message);
             }
             throw new InvalidOperationException("Error generating ", exception1);
         }
     }
     finally
     {
         proxyCode = writer1.ToString();
         if (writer1 != null)
         {
             writer1.Close();
         }
     }
 }
开发者ID:irdetocustomercentral,项目名称:WebServiceStudio,代码行数:85,代码来源:Wsdl.cs

示例7: GenerateCode

 private void GenerateCode(ServiceDescriptionCollection sources, XmlSchemas schemas, string uriToWSDL, ICodeGenerator codeGen, string fileExtension)
 {
     this.proxyCode = " <ERROR> ";
     StringWriter w = null;
     this.compileUnit = new CodeCompileUnit();
     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
     importer.Schemas.Add(schemas);
     foreach (ServiceDescription description in sources)
     {
         importer.AddServiceDescription(description, "", "");
     }
     importer.Style = ServiceDescriptionImportStyle.Client;
     Protocol protocol = this.WsdlProperties.Protocol;
     importer.ProtocolName = this.WsdlProperties.Protocol.ToString();
     CodeNamespace namespace2 = new CodeNamespace(this.proxyNamespace);
     this.compileUnit.Namespaces.Add(namespace2);
     ServiceDescriptionImportWarnings warnings = importer.Import(namespace2, this.compileUnit);
     try
     {
         try
         {
             w = new StringWriter();
         }
         catch
         {
             throw;
         }
         MemoryStream stream = null;
         if (schemas.Count > 0)
         {
             this.compileUnit.ReferencedAssemblies.Add("System.Data.dll");
             foreach (XmlSchema schema in schemas)
             {
                 string targetNamespace = null;
                 try
                 {
                     targetNamespace = schema.TargetNamespace;
                     if (XmlSchemas.IsDataSet(schema))
                     {
                         if (stream == null)
                         {
                             stream = new MemoryStream();
                         }
                         stream.Position = 0L;
                         stream.SetLength(0L);
                         schema.Write(stream);
                         stream.Position = 0L;
                         DataSet dataSet = new DataSet();
                         dataSet.ReadXmlSchema(stream);
                         TypedDataSetGenerator.Generate(dataSet, namespace2, codeGen);
                     }
                     continue;
                 }
                 catch
                 {
                     throw;
                 }
             }
         }
         try
         {
             GenerateVersionComment(this.compileUnit.Namespaces[0]);
             this.ChangeBaseType(this.compileUnit);
             codeGen.GenerateCodeFromCompileUnit(this.compileUnit, w, null);
         }
         catch (Exception exception)
         {
             if (w != null)
             {
                 w.Write("Exception in generating code");
                 w.Write(exception.Message);
             }
             throw new InvalidOperationException("Error generating ", exception);
         }
     }
     finally
     {
         this.proxyCode = w.ToString();
         if (w != null)
         {
             w.Close();
         }
     }
 }
开发者ID:zerostone,项目名称:webservicestudio,代码行数:84,代码来源:Wsdl.cs


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