Exemplo n.º 1
0
        internal string GenerateCode(
            VirtualPath virtualPath, string virtualFileString, out IDictionary linePragmasTable)
        {
            AddPendingCall();
            try {
                string             code = null;
                Type               codeDomProviderType;
                CompilerParameters compilerParameters;

                CodeCompileUnit ccu = GenerateCodeCompileUnit(virtualPath, virtualFileString, out codeDomProviderType,
                                                              out compilerParameters, out linePragmasTable);

                if (ccu != null && codeDomProviderType != null)
                {
                    CodeDomProvider codeProvider = CompilationUtil.CreateCodeDomProvider(codeDomProviderType);

                    CodeGeneratorOptions codeGeneratorOptions = new CodeGeneratorOptions();
                    codeGeneratorOptions.BlankLinesBetweenMembers = false;
                    codeGeneratorOptions.IndentString             = string.Empty;

                    StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
                    codeProvider.GenerateCodeFromCompileUnit(ccu, sw, codeGeneratorOptions);

                    code = sw.ToString();
                }

                return(code);
            }
            finally {
                RemovePendingCall();
            }
        }
        internal string GenerateCode(VirtualPath virtualPath, string virtualFileString, out IDictionary linePragmasTable)
        {
            string str2;

            this.AddPendingCall();
            try
            {
                Type type;
                CompilerParameters parameters;
                string             str         = null;
                CodeCompileUnit    compileUnit = this.GenerateCodeCompileUnit(virtualPath, virtualFileString, out type, out parameters, out linePragmasTable);
                if ((compileUnit != null) && (type != null))
                {
                    CodeDomProvider      provider = CompilationUtil.CreateCodeDomProvider(type);
                    CodeGeneratorOptions options  = new CodeGeneratorOptions {
                        BlankLinesBetweenMembers = false,
                        IndentString             = string.Empty
                    };
                    StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
                    provider.GenerateCodeFromCompileUnit(compileUnit, writer, options);
                    str = writer.ToString();
                }
                str2 = str;
            }
            finally
            {
                this.RemovePendingCall();
            }
            return(str2);
        }