Пример #1
0
        static void Main(string[] args)
        {
            foreach (CompilerInfo ci in CodeDomProvider.GetAllCompilerInfo())
            {
                foreach (string lang in ci.GetLanguages())
                {
                    Console.Write($"{lang} \t");
                }
                Console.WriteLine();
            }

            CodeNamespace progNamespace   = HelloWorldCodeDOM.BuildProgram();
            var           compilerOptions = new CodeGeneratorOptions
            {
                IndentString             = "  ",
                BracingStyle             = "C",
                BlankLinesBetweenMembers = false
            };

            AddMyClass(progNamespace);

            var codeText = new StringBuilder();

            using (var codeWriter = new StringWriter(codeText))
            {
                CodeDomProvider.CreateProvider("c#").GenerateCodeFromNamespace(progNamespace, codeWriter, compilerOptions);
            }
            var script = codeText.ToString();

            Console.WriteLine(script);
        }
Пример #2
0
        private void ListSupportedLanguages()
        {
            // Loop through information about all compilers.
            CompilerInfo[] compiler_infos =
                CodeDomProvider.GetAllCompilerInfo();
            foreach (CompilerInfo info in compiler_infos)
            {
                if (info.IsCodeDomProviderTypeValid)
                {
                    // Get information about this compiler.
                    CodeDomProvider provider = info.CreateProvider();

                    //string extensions = "";
                    string default_extension = provider.FileExtension;
                    if (default_extension[0] != '.')
                    {
                        default_extension = '.' + default_extension;
                    }

                    string default_language =
                        CodeDomProvider.GetLanguageFromExtension(default_extension);

                    toolStripComboBoxLang.Items.Add(default_language);
                }
            }
            if (toolStripComboBoxLang.Items.Count > 0)
            {
                toolStripComboBoxLang.SelectedIndex = 0;
            }
        }
Пример #3
0
        private void SupportedLanguages()
        {
            CompilerInfo[] aCompilerInfo = CodeDomProvider.GetAllCompilerInfo();

            foreach (CompilerInfo oCompilerInfo in aCompilerInfo)
            {
                foreach (string szLanguage in oCompilerInfo.GetLanguages())
                {
                    MessageBox.Show(szLanguage);
                }
            }

            if (!CodeDomProvider.IsDefinedLanguage("GW-BASIC"))
            {
                MessageBox.Show("GW-BASIC Not supported");
            }

            if (!CodeDomProvider.IsDefinedLanguage("CSharp"))
            {
                MessageBox.Show("CSharp Not supported");
            }

            if (!CodeDomProvider.IsDefinedExtension(".BAS"))
            {
                MessageBox.Show(".BAS Not supported");
            }

            if (!CodeDomProvider.IsDefinedExtension(".cs"))
            {
                MessageBox.Show(".cs Not supported");
            }
        }
Пример #4
0
        private static void Main()
        {
            var integratedFeatures = CodeDomProvider.GetAllCompilerInfo()
                                     .Aggregate(string.Empty, (current, compilerInfo) => current + GetCompilerInfo(compilerInfo));

            Console.WriteLine(integratedFeatures);
        }
Пример #5
0
        private static void Usage()
        {
            Console.WriteLine(SR.GetString(SR.Usage, Environment.Version, CommonResStrings.CopyrightForCmdLine));

            Console.WriteLine(SR.GetString(SR.ValidLanguages));

            CompilerInfo[] compilerInfos = CodeDomProvider.GetAllCompilerInfo();
            for (int i = 0; i < compilerInfos.Length; i++)
            {
                string[] languages = compilerInfos[i].GetLanguages();
                if (i != 0)
                {
                    Console.Write(", ");
                }

                for (int j = 0; j < languages.Length; j++)
                {
                    if (j != 0)
                    {
                        Console.Write(", ");
                    }
                    Console.Write(languages[j]);
                }
            }
            Console.WriteLine();
        }
 static void Main()
 {
     foreach (CompilerInfo ci in
              CodeDomProvider.GetAllCompilerInfo())
     {
         StringBuilder output   = new StringBuilder();
         string        language = ci.GetLanguages()[0];
         output.AppendFormat("{0} features:\r\n", language);
         try
         {
             CodeDomProvider provider = CodeDomProvider
                                        .CreateProvider(language);
             output.AppendFormat("CaseInsensitive = {0}\r\n",
                                 provider.LanguageOptions.HasFlag(
                                     LanguageOptions.CaseInsensitive));
             foreach (GeneratorSupport supportableFeature
                      in Enum.GetValues(typeof(GeneratorSupport)))
             {
                 output.AppendFormat("{0} = {1}\r\n",
                                     supportableFeature,
                                     provider.Supports(supportableFeature));
             }
         }
         catch (Exception ex)
         {
             output.AppendFormat("{0} occurred while getting " +
                                 "features for language {1} with the following " +
                                 "message:\r\n\r\n'{2}'.\r\n", ex.GetType().Name,
                                 language, ex.Message);
         }
         Console.WriteLine(output.ToString());
     }
     Console.ReadLine();
 }
Пример #7
0
 public void GetAllCompilerInfo_ReturnsMinimumOfCSharpAndVB()
 {
     Type[] compilerInfos = CodeDomProvider.GetAllCompilerInfo().Where(provider => provider.IsCodeDomProviderTypeValid).Select(provider => provider.CodeDomProviderType).ToArray();
     Assert.True(compilerInfos.Length >= 2);
     Assert.Contains(typeof(CSharpCodeProvider), compilerInfos);
     Assert.Contains(typeof(VBCodeProvider), compilerInfos);
 }
Пример #8
0
 static void Main(string[] args)
 {
     foreach (CompilerInfo ci in CodeDomProvider.GetAllCompilerInfo())
     {
         foreach (string lang in ci.GetLanguages())
         {
             System.Console.Write("{0} ", lang);
         }
         System.Console.WriteLine();
     }
 }
Пример #9
0
        static void DisplayAllCompilerInfo()
        {
            // <Snippet8>
            CompilerInfo [] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo();
            foreach (CompilerInfo info in allCompilerInfo)
            {
                String defaultLanguage;
                String defaultExtension;

                CodeDomProvider provider = info.CreateProvider();

                // Display information about this configured provider.

                Console.WriteLine("Language provider:  {0}",
                                  provider.ToString());
                Console.WriteLine();

                Console.WriteLine("  Supported file extension(s):");
                foreach (String extension in info.GetExtensions())
                {
                    Console.WriteLine("    {0}", extension);
                }

                defaultExtension = provider.FileExtension;
                if (defaultExtension[0] != '.')
                {
                    defaultExtension = "." + defaultExtension;
                }
                Console.WriteLine("  Default file extension:  {0}",
                                  defaultExtension);
                Console.WriteLine();

                Console.WriteLine("  Supported language(s):");
                foreach (String language in info.GetLanguages())
                {
                    Console.WriteLine("    {0}", language);
                }

                defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension);
                Console.WriteLine("  Default language:        {0}",
                                  defaultLanguage);
                Console.WriteLine();

                // Get the compiler settings for this provider.
                CompilerParameters langCompilerConfig = info.CreateDefaultCompilerParameters();

                Console.WriteLine("  Compiler options:        {0}",
                                  langCompilerConfig.CompilerOptions);
                Console.WriteLine("  Compiler warning level:  {0}",
                                  langCompilerConfig.WarningLevel);
                Console.WriteLine();
            }
            // </Snippet8>
        }
Пример #10
0
 static void ShowInstalledLanguages()
 {
     foreach (CompilerInfo ci in CodeDomProvider.GetAllCompilerInfo())
     {
         foreach (string language in ci.GetLanguages())
         {
             Console.Write(language + " \t");
         }
         Console.WriteLine();
     }
 }
Пример #11
0
 public void TestMethod1()
 {
     CompilerInfo[] infos = CodeDomProvider.GetAllCompilerInfo();
     foreach (CompilerInfo info in infos)
     {
         string[] strs = info.GetLanguages();
         foreach (string str in strs)
         {
             Console.WriteLine(str);
         }
     }
 }
        static void Main(string[] args)
        {
            CompilerInfo[] aCompilerInfo = CodeDomProvider.GetAllCompilerInfo();

            foreach (CompilerInfo oCompilerInfo in aCompilerInfo)
            {
                foreach (string szLanguage in oCompilerInfo.GetLanguages())
                {
                    Console.Write(szLanguage + "\n");
                }
            }
        }
Пример #13
0
        private CodeDomProvider CreateCodeDomProvider(string language)
        {
            foreach (var compiler in CodeDomProvider.GetAllCompilerInfo( ))
            {
                foreach (var compilerLanguage in compiler.GetLanguages( ))
                {
                    if (string.Equals(language, compilerLanguage, StringComparison.OrdinalIgnoreCase))
                    {
                        return(CodeDomProvider.CreateProvider(compilerLanguage));
                    }
                }
            }

            Log.LogError($"Unable to find a CodeDomProvider for language { language }.");

            return(null);
        }
Пример #14
0
        public void Defaults()
        {
            cdp = new CodeDomProviderTest();              // execute ctor not a full trust
            Assert.AreEqual(String.Empty, cdp.FileExtension, "FileExtension");
            Assert.AreEqual(LanguageOptions.None, cdp.LanguageOptions, "LanguageOptions");
            Assert.IsNull(cdp.CreateCompiler(), "CreateCompiler");
            Assert.IsNull(cdp.CreateGenerator(), "CreateGenerator");
            Assert.IsNull(cdp.CreateGenerator(String.Empty), "CreateGenerator(string)");
            Assert.IsNull(cdp.CreateGenerator(writer), "CreateGenerator(TextWriter)");
            Assert.IsNull(cdp.CreateParser(), "CreateParser()");
            Assert.IsNotNull(cdp.GetConverter(typeof(string)), "GetConverter");
            Assert.IsNotNull(CodeDomProvider.GetAllCompilerInfo(), "GetAllCompilerInfo");

            // mono returns null (missing config?)
            CodeDomProvider.GetCompilerInfo("cs");
            CodeDomProvider.GetLanguageFromExtension("cs");

            Assert.IsFalse(CodeDomProvider.IsDefinedExtension(String.Empty), "String.Empty");
            Assert.IsFalse(CodeDomProvider.IsDefinedLanguage(String.Empty), "String.Empty");
        }
Пример #15
0
        static void Main(String[] args)
        {
            CodeNamespace prgNameSpace    = BuildProgram();
            var           compilerOptions = new CodeGeneratorOptions()
            {
                IndentString             = " ",
                BracingStyle             = "C",
                BlankLinesBetweenMembers = false
            };

            foreach (CompilerInfo ci in CodeDomProvider.GetAllCompilerInfo())
            {
                var    codeText = new StringBuilder();
                String ln       = ci.GetLanguages()[0];
                using (var codeWriter = new StringWriter(codeText))
                {
                    CodeDomProvider.CreateProvider(ln)
                    .GenerateCodeFromNamespace(prgNameSpace, codeWriter, compilerOptions);
                }
                Console.WriteLine("lang is " + ln);
                Console.WriteLine(codeText.ToString());
                Console.WriteLine();
            }
        }
Пример #16
0
        internal static long GetRecompilationHash(CompilationSection ps)
        {
            HashCodeCombiner                   recompilationHash = new HashCodeCombiner();
            AssemblyCollection                 assemblies;
            BuildProviderCollection            builders;
            FolderLevelBuildProviderCollection buildProviders;
            CodeSubDirectoriesCollection       codeSubDirs;

            // Combine items from Compilation section
            recompilationHash.AddObject(ps.Debug);
            recompilationHash.AddObject(ps.TargetFramework);
            recompilationHash.AddObject(ps.Strict);
            recompilationHash.AddObject(ps.Explicit);
            recompilationHash.AddObject(ps.Batch);
            recompilationHash.AddObject(ps.OptimizeCompilations);
            recompilationHash.AddObject(ps.BatchTimeout);
            recompilationHash.AddObject(ps.MaxBatchGeneratedFileSize);
            recompilationHash.AddObject(ps.MaxBatchSize);
            recompilationHash.AddObject(ps.NumRecompilesBeforeAppRestart);
            recompilationHash.AddObject(ps.DefaultLanguage);
            recompilationHash.AddObject(ps.UrlLinePragmas);
            recompilationHash.AddObject(ps.DisableObsoleteWarnings);
            if (ps.AssemblyPostProcessorTypeInternal != null)
            {
                recompilationHash.AddObject(ps.AssemblyPostProcessorTypeInternal.FullName);
            }
            if (!String.IsNullOrWhiteSpace(ps.ControlBuilderInterceptorType))
            {
                recompilationHash.AddObject(ps.ControlBuilderInterceptorType);
            }

            // Combine items from Compilers collection
            foreach (Compiler compiler in ps.Compilers)
            {
                recompilationHash.AddObject(compiler.Language);
                recompilationHash.AddObject(compiler.Extension);
                recompilationHash.AddObject(compiler.Type);
                recompilationHash.AddObject(compiler.WarningLevel);
                recompilationHash.AddObject(compiler.CompilerOptions);
            }

            // Combine items from <expressionBuilders> section
            foreach (System.Web.Configuration.ExpressionBuilder eb in ps.ExpressionBuilders)
            {
                recompilationHash.AddObject(eb.ExpressionPrefix);
                recompilationHash.AddObject(eb.Type);
            }

            // Combine items from the Assembly collection
            assemblies = ps.Assemblies;

            if (assemblies.Count == 0)
            {
                recompilationHash.AddObject("__clearassemblies");
            }
            else
            {
                foreach (AssemblyInfo ai in assemblies)
                {
                    recompilationHash.AddObject(ai.Assembly);
                }
            }

            // Combine items from the Builders Collection
            builders = ps.BuildProviders;

            if (builders.Count == 0)
            {
                recompilationHash.AddObject("__clearbuildproviders");
            }
            else
            {
                foreach (System.Web.Configuration.BuildProvider bp in builders)
                {
                    recompilationHash.AddObject(bp.Type);
                    recompilationHash.AddObject(bp.Extension);
                }
            }

            // Combine items from the FolderLevelBuildProviderCollection
            buildProviders = ps.FolderLevelBuildProviders;

            if (buildProviders.Count == 0)
            {
                recompilationHash.AddObject("__clearfolderlevelbuildproviders");
            }
            else
            {
                foreach (System.Web.Configuration.FolderLevelBuildProvider bp in buildProviders)
                {
                    recompilationHash.AddObject(bp.Type);
                    recompilationHash.AddObject(bp.Name);
                }
            }

            codeSubDirs = ps.CodeSubDirectories;
            if (codeSubDirs.Count == 0)
            {
                recompilationHash.AddObject("__clearcodesubdirs");
            }
            else
            {
                foreach (CodeSubDirectory csd in codeSubDirs)
                {
                    recompilationHash.AddObject(csd.DirectoryName);
                }
            }

            // Make sure the <system.CodeDom> section is hashed properly.
            CompilerInfo[] compilerInfoArray = CodeDomProvider.GetAllCompilerInfo();
            if (compilerInfoArray != null)
            {
                CompilerInfo cppCodeProvider = CodeDomProvider.GetCompilerInfo("cpp");
                foreach (CompilerInfo info in compilerInfoArray)
                {
                    // Skip cpp code provider (Dev11 193323).
                    if (info == cppCodeProvider)
                    {
                        continue;
                    }

                    // Ignore it if the type is not valid.
                    if (!info.IsCodeDomProviderTypeValid)
                    {
                        continue;
                    }

                    CompilerParameters parameters = info.CreateDefaultCompilerParameters();
                    string             option     = parameters.CompilerOptions;
                    if (!String.IsNullOrEmpty(option))
                    {
                        Type type = info.CodeDomProviderType;
                        if (type != null)
                        {
                            recompilationHash.AddObject(type.FullName);
                        }
                        // compilerOptions need to be hashed.
                        recompilationHash.AddObject(option);
                    }

                    // DevDiv 62998
                    // The tag providerOption needs to be added to the hash,
                    // as the user could switch between v2 and v3.5.
                    if (info.CodeDomProviderType == null)
                    {
                        continue;
                    }

                    // Add a hash for each providerOption added, specific for each codeDomProvider, so that
                    // if some codedom setting has changed, we know we have to recompile.
                    IDictionary <string, string> providerOptions = GetProviderOptions(info);
                    if (providerOptions != null && providerOptions.Count > 0)
                    {
                        string codeDomProviderType = info.CodeDomProviderType.FullName;
                        foreach (string key in providerOptions.Keys)
                        {
                            string value = providerOptions[key];
                            recompilationHash.AddObject(codeDomProviderType + ":" + key + "=" + value);
                        }
                    }
                }
            }

            return(recompilationHash.CombinedHash);
        }
Пример #17
0
        internal static long GetRecompilationHash(CompilationSection ps)
        {
            HashCodeCombiner combiner = new HashCodeCombiner();

            combiner.AddObject(ps.Debug);
            combiner.AddObject(ps.TargetFramework);
            combiner.AddObject(ps.Strict);
            combiner.AddObject(ps.Explicit);
            combiner.AddObject(ps.Batch);
            combiner.AddObject(ps.OptimizeCompilations);
            combiner.AddObject(ps.BatchTimeout);
            combiner.AddObject(ps.MaxBatchGeneratedFileSize);
            combiner.AddObject(ps.MaxBatchSize);
            combiner.AddObject(ps.NumRecompilesBeforeAppRestart);
            combiner.AddObject(ps.DefaultLanguage);
            combiner.AddObject(ps.UrlLinePragmas);
            if (ps.AssemblyPostProcessorTypeInternal != null)
            {
                combiner.AddObject(ps.AssemblyPostProcessorTypeInternal.FullName);
            }
            foreach (Compiler compiler in ps.Compilers)
            {
                combiner.AddObject(compiler.Language);
                combiner.AddObject(compiler.Extension);
                combiner.AddObject(compiler.Type);
                combiner.AddObject(compiler.WarningLevel);
                combiner.AddObject(compiler.CompilerOptions);
            }
            foreach (System.Web.Configuration.ExpressionBuilder builder in ps.ExpressionBuilders)
            {
                combiner.AddObject(builder.ExpressionPrefix);
                combiner.AddObject(builder.Type);
            }
            AssemblyCollection assemblies = ps.Assemblies;

            if (assemblies.Count == 0)
            {
                combiner.AddObject("__clearassemblies");
            }
            else
            {
                foreach (AssemblyInfo info in assemblies)
                {
                    combiner.AddObject(info.Assembly);
                }
            }
            BuildProviderCollection buildProviders = ps.BuildProviders;

            if (buildProviders.Count == 0)
            {
                combiner.AddObject("__clearbuildproviders");
            }
            else
            {
                foreach (System.Web.Configuration.BuildProvider provider in buildProviders)
                {
                    combiner.AddObject(provider.Type);
                    combiner.AddObject(provider.Extension);
                }
            }
            FolderLevelBuildProviderCollection folderLevelBuildProviders = ps.FolderLevelBuildProviders;

            if (folderLevelBuildProviders.Count == 0)
            {
                combiner.AddObject("__clearfolderlevelbuildproviders");
            }
            else
            {
                foreach (FolderLevelBuildProvider provider2 in folderLevelBuildProviders)
                {
                    combiner.AddObject(provider2.Type);
                    combiner.AddObject(provider2.Name);
                }
            }
            CodeSubDirectoriesCollection codeSubDirectories = ps.CodeSubDirectories;

            if (codeSubDirectories.Count == 0)
            {
                combiner.AddObject("__clearcodesubdirs");
            }
            else
            {
                foreach (CodeSubDirectory directory in codeSubDirectories)
                {
                    combiner.AddObject(directory.DirectoryName);
                }
            }
            CompilerInfo[] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo();
            if (allCompilerInfo != null)
            {
                foreach (CompilerInfo info2 in allCompilerInfo)
                {
                    if (info2.IsCodeDomProviderTypeValid)
                    {
                        string compilerOptions = info2.CreateDefaultCompilerParameters().CompilerOptions;
                        if (!string.IsNullOrEmpty(compilerOptions))
                        {
                            Type codeDomProviderType = info2.CodeDomProviderType;
                            if (codeDomProviderType != null)
                            {
                                combiner.AddObject(codeDomProviderType.FullName);
                            }
                            combiner.AddObject(compilerOptions);
                        }
                        if (info2.CodeDomProviderType != null)
                        {
                            IDictionary <string, string> providerOptions = GetProviderOptions(info2);
                            if ((providerOptions != null) && (providerOptions.Count > 0))
                            {
                                string fullName = info2.CodeDomProviderType.FullName;
                                foreach (string str3 in providerOptions.Keys)
                                {
                                    string str4 = providerOptions[str3];
                                    combiner.AddObject(fullName + ":" + str3 + "=" + str4);
                                }
                            }
                        }
                    }
                }
            }
            return(combiner.CombinedHash);
        }