Beispiel #1
0
        static ArrayList GenerateCodeToExposeStandardBindingToConfig()
        {
            string    indent         = "    ";
            ArrayList generatedFiles = null;

            if (stdBindingType != null)
            {
                stdBindingElementSrcFile = stdBindingType.Name + Constants.ElementSuffix + "." + provider.FileExtension;
                using (StreamWriter stdBindingElementSW = new StreamWriter(stdBindingElementSrcFile, false))
                {
                    using (IndentedTextWriter sbtw = new IndentedTextWriter(stdBindingElementSW, indent))
                    {
                        StandardBindingSectionGenerator stdBindingElementGen = new StandardBindingSectionGenerator(stdBindingType, userAssembly, provider);
                        provider.GenerateCodeFromCompileUnit(
                            stdBindingElementGen.BuildCodeGraph(out generatedFiles),
                            sbtw,
                            new CodeGeneratorOptions());
                        generatedSBCollectionElementClassName = stdBindingElementGen.NamespaceOfGeneratedClass + "." + stdBindingElementGen.GeneratedCollectionElementClassName;
                        additionalCodeForStdBindingFile       = "CodeToAddTo" + stdBindingType.Name + "." + provider.FileExtension;
                        // Since the ApplyConfigurationMethod has to be added to the custom standard binding
                        // class, let's spit out the code they need to add on the screen
                        UserTypeCodeEnhancer.EmitCodeToAddIntoCustomStdBinding(
                            stdBindingType,
                            stdBindingElementGen.GeneratedElementClassName,
                            stdBindingElementGen.GeneratedCollectionElementClassName,
                            additionalCodeForStdBindingFile);
                        generatedFiles.Add(additionalCodeForStdBindingFile);
                        Console.WriteLine("Add this code to your custom standard binding; this code has been generated in the file " + additionalCodeForStdBindingFile);
                        Helpers.DisplayFile(additionalCodeForStdBindingFile);
                        Console.WriteLine("You will need to add using System.Globalization; and using System.Configuration; to your custom standard binding code too");
                        Console.WriteLine("You will also need to reference System.Configuration.dll");
                        Console.WriteLine("-------------------");
                    }
                }
                generatedFiles.Add(stdBindingElementSrcFile);
                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);
                }
                //}
            }
            return(generatedFiles);
        }
Beispiel #2
0
        static ArrayList GenerateCodeToExposeStandardBindingToConfig()
        {
            string indent = "    ";
            ArrayList generatedFiles = null;

            if (stdBindingType != null)
            {
                stdBindingElementSrcFile = stdBindingType.Name + Constants.ElementSuffix + "." + provider.FileExtension;
                using (StreamWriter stdBindingElementSW = new StreamWriter(stdBindingElementSrcFile, false))
                {
                    using (IndentedTextWriter sbtw = new IndentedTextWriter(stdBindingElementSW, indent))
                    {
                        StandardBindingSectionGenerator stdBindingElementGen = new StandardBindingSectionGenerator(stdBindingType, userAssembly, provider);
                        provider.GenerateCodeFromCompileUnit(
                            stdBindingElementGen.BuildCodeGraph(out generatedFiles),
                            sbtw,
                            new CodeGeneratorOptions());
                        generatedSBCollectionElementClassName = stdBindingElementGen.NamespaceOfGeneratedClass + "." + stdBindingElementGen.GeneratedCollectionElementClassName;
                        additionalCodeForStdBindingFile = "CodeToAddTo" + stdBindingType.Name + "." + provider.FileExtension;
                        // Since the ApplyConfigurationMethod has to be added to the custom standard binding
                        // class, let's spit out the code they need to add on the screen
                        UserTypeCodeEnhancer.EmitCodeToAddIntoCustomStdBinding(
                                            stdBindingType,
                                            stdBindingElementGen.GeneratedElementClassName,
                                            stdBindingElementGen.GeneratedCollectionElementClassName,
                                            additionalCodeForStdBindingFile);
                        generatedFiles.Add(additionalCodeForStdBindingFile);
                        Console.WriteLine("Add this code to your custom standard binding; this code has been generated in the file " + additionalCodeForStdBindingFile); 
                        Helpers.DisplayFile(additionalCodeForStdBindingFile);
                        Console.WriteLine("You will need to add using System.Globalization; and using System.Configuration; to your custom standard binding code too");
                        Console.WriteLine("You will also need to reference System.Configuration.dll");
                        Console.WriteLine("-------------------");
                    }
                }
                generatedFiles.Add(stdBindingElementSrcFile);
                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);
                    }
                //}
            }
            return generatedFiles;
        }