コード例 #1
0
        static ArrayList GenerateCodeToExposeBindingElementToConfig()
        {
            string    indent         = "    ";
            ArrayList generatedFiles = null;

            if (bindingElementType != null)
            {
                bindingElementExtensionSectionSrcFile = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ElementSuffix + "." + provider.FileExtension;
                using (StreamWriter bindingElementExtensionSectionSW = new StreamWriter(bindingElementExtensionSectionSrcFile, false))
                {
                    using (IndentedTextWriter betw = new IndentedTextWriter(bindingElementExtensionSectionSW, indent))
                    {
                        BindingElementExtensionSectionGenerator bindingElementExtensionSectionGen = new BindingElementExtensionSectionGenerator(bindingElementType, userAssembly, provider);
                        provider.GenerateCodeFromCompileUnit(
                            bindingElementExtensionSectionGen.BuildCodeGraph(out generatedFiles),
                            betw,
                            new CodeGeneratorOptions());
                        generatedBEElementClassName = bindingElementExtensionSectionGen.NamespaceOfGeneratedClass + "." + bindingElementExtensionSectionGen.GeneratedClassName;
                    }
                }
                generatedFiles.Add(bindingElementExtensionSectionSrcFile);
                string[] generatedFilesArr = new string[generatedFiles.Count];
                generatedFiles.CopyTo(0, generatedFilesArr, 0, generatedFiles.Count);

                /*
                 * Currently the sample does not pick default values for const fields, so compiling the
                 * generated code will result in compilation errors.
                 * If the sample is updated to provide default values for const fields, the following should
                 * be uncommented. The code which needs to be updated is in
                 * CodeDomCommon.cs - CodeGenHelperMethods.EmitDefaultValuesClass
                 */

                //if (Helpers.CompileCode(provider, userAssembly, generatedFilesArr))
                //{
                //    // display the generated code
                foreach (string fileName in generatedFilesArr)
                {
                    Helpers.DisplayFile(fileName);
                }
                //}
            }
            Console.WriteLine("-------------------");
            return(generatedFiles);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ssickles/archive
        static ArrayList GenerateCodeToExposeBindingElementToConfig()
        {
            string indent = "    ";
            ArrayList generatedFiles = null;

            if (bindingElementType != null)
            {
                bindingElementExtensionSectionSrcFile = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ElementSuffix + "." + provider.FileExtension;
                using (StreamWriter bindingElementExtensionSectionSW = new StreamWriter(bindingElementExtensionSectionSrcFile, false))
                {
                    using (IndentedTextWriter betw = new IndentedTextWriter(bindingElementExtensionSectionSW, indent))
                    {
                        BindingElementExtensionSectionGenerator bindingElementExtensionSectionGen = new BindingElementExtensionSectionGenerator(bindingElementType, userAssembly, provider);
                        provider.GenerateCodeFromCompileUnit(
                            bindingElementExtensionSectionGen.BuildCodeGraph(out generatedFiles),
                            betw,
                            new CodeGeneratorOptions());
                        generatedBEElementClassName = bindingElementExtensionSectionGen.NamespaceOfGeneratedClass + "." + bindingElementExtensionSectionGen.GeneratedClassName;
                    }
                }
                generatedFiles.Add(bindingElementExtensionSectionSrcFile);
                string[] generatedFilesArr = new string[generatedFiles.Count];
                generatedFiles.CopyTo(0, generatedFilesArr, 0, generatedFiles.Count);

                /* 
                 * Currently the sample does not pick default values for const fields, so compiling the
                 * generated code will result in compilation errors.
                 * If the sample is updated to provide default values for const fields, the following should
                 * be uncommented. The code which needs to be updated is in 
	         * CodeDomCommon.cs - CodeGenHelperMethods.EmitDefaultValuesClass
                 */

                //if (Helpers.CompileCode(provider, userAssembly, generatedFilesArr))
                //{
                //    // display the generated code
                      foreach (string fileName in generatedFilesArr)
                      {
                          Helpers.DisplayFile(fileName);
                      }
                //}
            }
            Console.WriteLine("-------------------");
            return generatedFiles;
        }