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


C# Microsoft.CSharp.CSharpCodeProvider.GenerateCodeFromNamespace方法代码示例

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


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

示例1: GenTableAdapters

        public static string GenTableAdapters(System.IO.Stream xmlStream, TypedDataSetGenerator.GenerateOption genOption, string customToolNamespace)
        {
            try
            {

                EnsureCustomDbProviders();
                var designSource = Activator.CreateInstance(assm.GetType("System.Data.Design.DesignDataSource"));
                designSource.Invoke("ReadXmlSchema",  xmlStream, string.Empty );
                var dataSourceGeneratorType = assm.GetType("System.Data.Design.TypedDataSourceCodeGenerator");
                //get the specific constructor
                var constructor = dataSourceGeneratorType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic,
                    null, CallingConventions.Any, new Type[0], new ParameterModifier[0]);
                var dataSourceGenerator = constructor.Invoke(null);

                var codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
                dataSourceGenerator.SetInternalPropertyValue("CodeProvider", codeProvider);

                var codeCompileUnit = new CodeCompileUnit();
                var codeNamespace = new CodeNamespace(customToolNamespace);
                codeCompileUnit.Namespaces.Add(codeNamespace);

                dataSourceGenerator.InvokeInternal("GenerateDataSource",  designSource, codeCompileUnit, codeNamespace, customToolNamespace, genOption );
                var writer = new StringWriter();
                var adapterNameSpace = codeCompileUnit.Namespaces[1];
                codeProvider.GenerateCodeFromNamespace(adapterNameSpace, writer, new CodeGeneratorOptions());
                //codeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, writer, options);
                var res = writer.ToString();
                return (string)res;
            }
            catch (Exception e)
            {

                return e.ToString();
            }
        }
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:35,代码来源:DatasetGeneratorWrapper.cs

示例2: service_info_methods

        public static void service_info_methods()
        {
            uri = new Uri("http://localhost:60377/Service1.asmx?wsdl"); 
            WebRequest webRequest = WebRequest.Create(uri);
            System.IO.Stream requestStream = webRequest.GetResponse().GetResponseStream();
            // Get a WSDL file describing a service
            ServiceDescription sd = ServiceDescription.Read(requestStream);
            string sdName = sd.Services[0].Name;

            // Initialize a service description servImport
            ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();
            servImport.AddServiceDescription(sd, String.Empty, String.Empty);
            servImport.ProtocolName = "Soap";
            servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;

            CodeNamespace nameSpace = new CodeNamespace();
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
            codeCompileUnit.Namespaces.Add(nameSpace);
            // Set Warnings
            ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);

            if (warnings == 0)
            {
                StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
                Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider();
                prov.GenerateCodeFromNamespace(nameSpace, stringWriter, new CodeGeneratorOptions());

                string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
                CompilerParameters param = new CompilerParameters(assemblyReferences);
                param.GenerateExecutable = false;
                param.GenerateInMemory = true;
                param.TreatWarningsAsErrors = false;
                param.WarningLevel = 4;

                CompilerResults results = new CompilerResults(new TempFileCollection());
                results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
                Assembly assembly = results.CompiledAssembly;
                service = assembly.GetType(sdName);

                methodInfo = service.GetMethods();

                int c = 0;
                foreach (MethodInfo t in methodInfo)
                {
                    if (t.Name == "Discover")
                        break;
                    c++;
                }
                listurl = new string[c]; c = 0;
                foreach (MethodInfo t in methodInfo)
                {
                    if (t.Name == "Discover")
                        break;
                    listurl[c++] = t.Name;
                }

            }

        }
开发者ID:MinaYounan-CS,项目名称:WoT-Testbed-Environment,代码行数:59,代码来源:Service+Info.cs

示例3: Main

        public static void Main(string[] args)
        {
            string schemaFilename  = @"..\doc\COLLADASchema_141.xsd";
            string targetFilename  = @"..\lib\Collada\Collada\Autogenerated\Collada.cs";
            string targetNamespace = @"Collada";

            // Generate CodeDOM classes
            CodeNamespace code;
            using(FileStream schemaStream = new FileStream(schemaFilename, FileMode.Open)) {
                code = GenerateCode(schemaStream, targetNamespace);
            }

            // Write classes to file
            CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
            using(StreamWriter writer = new StreamWriter(targetFilename, false)) {
                provider.GenerateCodeFromNamespace(code, writer, new CodeGeneratorOptions());
            }
        }
开发者ID:dsrbecky,项目名称:ColladaDOM,代码行数:18,代码来源:Main.cs

示例4: GenerateCode


//.........这里部分代码省略.........
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Input"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Media"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Media.Animation"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Media.Imaging"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Shapes"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Renderers"));
            ns.Imports.Add(new CodeNamespaceImport("EmptyKeys.UserInterface.Themes"));

            /*
            switch (renderMode)
            {
                case RenderMode.SunBurn:
                    ns.Imports.Add(new CodeNamespaceImport("SynapseGaming.SunBurn.Framework.Primitives"));
                    break;
                case RenderMode.MonoGame:
                    ns.Imports.Add(new CodeNamespaceImport("Microsoft.Xna.Framework"));
                    ns.Imports.Add(new CodeNamespaceImport("Microsoft.Xna.Framework.Graphics"));
                    break;
                default:
                    break;
            }
             */

            CodeTypeDeclaration classType = new CodeTypeDeclaration(className);

            GeneratedCodeAttribute generatedCodeAttribute =
            new GeneratedCodeAttribute("Empty Keys UI Generator", Assembly.GetExecutingAssembly().GetName().Version.ToString());

            CodeAttributeDeclaration codeAttrDecl =
                new CodeAttributeDeclaration(generatedCodeAttribute.GetType().Name,
                    new CodeAttributeArgument(
                        new CodePrimitiveExpression(generatedCodeAttribute.Tool)),
                    new CodeAttributeArgument(
                        new CodePrimitiveExpression(generatedCodeAttribute.Version)));
            classType.CustomAttributes.Add(codeAttrDecl);

            ns.Comments.Add(new CodeCommentStatement("-----------------------------------------------------------", false));
            ns.Comments.Add(new CodeCommentStatement(" ", false));
            ns.Comments.Add(new CodeCommentStatement(" This file was generated, please do not modify.", false));
            ns.Comments.Add(new CodeCommentStatement(" ", false));
            ns.Comments.Add(new CodeCommentStatement("-----------------------------------------------------------", false));

            CodeMemberMethod initMethod = null;
            if (source is UIRoot)
            {
                initMethod = CreateUIRootClass(ns, classType, renderMode);
                generator.ProcessGenerators(source, classType, initMethod, true);
            }
            else if (source is UserControl)
            {
                initMethod = CreateUserControlClass(ns, classType);
                generator.ProcessGenerators(source, classType, initMethod, true);
            }
            else if (source is ResourceDictionary)
            {
                initMethod = CreateDictionaryClass(ns, classType);

                ResourceDictionary dictionary = source as ResourceDictionary;
                if (dictionary != null)
                {
                    ResourceDictionaryGenerator resourcesGenerator = new ResourceDictionaryGenerator();
                    resourcesGenerator.Generate(dictionary, classType, initMethod, new CodeThisReferenceExpression());
                }
            }
            else
            {
                string errorText = "#error This type is not supported - " + source.GetType();
                Console.WriteLine(errorText);
                return errorText;
            }

            ImageAssets.Instance.GenerateManagerCode(initMethod);
            ImageAssets.Instance.ClearAssets();

            FontGenerator.Instance.GenerateManagerCode(initMethod);

            using (CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
            {
                string mappedFileName = memoryMappedFileName + className;
                using (MemoryMappedFile mappedFile = MemoryMappedFile.CreateNew(mappedFileName, nemoryMappedFileCapacity))
                {
                    MemoryMappedViewStream stream = mappedFile.CreateViewStream();

                    using (StreamWriter sw = new StreamWriter(stream))
                    {
                        provider.GenerateCodeFromNamespace(ns, sw, new CodeGeneratorOptions());
                    }

                    stream = mappedFile.CreateViewStream();

                    TextReader tr = new StreamReader(stream);
                    resultCode = tr.ReadToEnd();
                    resultCode = resultCode.Trim(new char());

                    tr.Close();
                }
            }

            return resultCode;
        }
开发者ID:bbqchickenrobot,项目名称:UI_Generator,代码行数:101,代码来源:UserInterfaceGenerator.cs

示例5: GenerateFile

        /// <summary>
        /// Generates the file.
        /// </summary>
        /// <param name="outputFile">The output file.</param>
        /// <exception cref="System.ArgumentNullException">Code not generated. Namespace is empty.</exception>
        public void GenerateFile(string outputFile)
        {
            if (ns == null)
            {
                throw new ArgumentNullException("Code not generated. Namespace is empty.");
            }

            string generatedCode = string.Empty;
            try
            {
                using (CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    using (MemoryMappedFile mappedFile = MemoryMappedFile.CreateNew(memoryMappedFileName, nemoryMappedFileCapacity))
                    {
                        MemoryMappedViewStream stream = mappedFile.CreateViewStream();

                        using (StreamWriter sw = new StreamWriter(stream))
                        {
                            provider.GenerateCodeFromNamespace(ns, sw, new CodeGeneratorOptions());
                        }

                        stream = mappedFile.CreateViewStream();

                        TextReader tr = new StreamReader(stream);
                        generatedCode = tr.ReadToEnd();
                        generatedCode = generatedCode.Trim(new char());

                        tr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                generatedCode = "#error " + ex.Message;
                throw;
            }
            finally
            {
                using (StreamWriter outfile = new StreamWriter(outputFile))
                {
                    outfile.Write(generatedCode);
                }
            }
        }
开发者ID:aravol,项目名称:UI_Generator,代码行数:49,代码来源:BindingGenerator.cs

示例6: RenderStatements

		private static void RenderStatements(CodeNamespace ns)
		{
			Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
			provider.GenerateCodeFromNamespace(ns, Console.Out, null);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:5,代码来源:XmlCodeRendererFixture.cs


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