Exemplo n.º 1
0
        static int Main(string[] args)
        {
            const string uniqueComment = "//asdfjwieowilsdkvmmweiowjaX";
            string       code;

            if (args.Length == 0)
            {
                code = new StreamReader(Console.OpenStandardInput()).ReadToEnd();
            }
            else
            {
                string path = args[0];

                if (!File.Exists(path))
                {
                    Console.Error.Write("File not found: {0}", path);
                    return(2);
                }

                code = File.ReadAllText(path);
            }

            // Commenting out conditional compile blocks, so they will be processed as well regardless of which symbol is defined.
            var ifPreprocessorRegX = new Regex("^#(if|elif|endif|else)", RegexOptions.Multiline | RegexOptions.ExplicitCapture);

            code = ifPreprocessorRegX.Replace(code, uniqueComment + @"$0");

            string processedCode = AnalyzerRunner.RunCodeFix("C#", new NullableReferenceTypeAnalyzer(), new NullableReferenceTypeCodeFixProvider(), code, true);

            Console.Write(processedCode.Replace(uniqueComment, ""));

            return(0);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            const string uniqueComment = "//asdfjwieowilsdkvmmweiowjaX";

            if (args.Length == 0)
            {
                Console.Error.Write("Tool must be supplied with the path to a .cs code file.");
                return(1);
            }
            string path = args[0];

            if (!File.Exists(path))
            {
                Console.Error.Write("File not found: {0}", path);
                return(2);
            }

            string code = File.ReadAllText(path);

            var ifPreprocessorRegX = new Regex("^#(if|elif|endif|else)", RegexOptions.Multiline | RegexOptions.ExplicitCapture);

            code = ifPreprocessorRegX.Replace(code, uniqueComment + @"$0");

            string processedCode = AnalyzerRunner.RunCodeFix("C#", new NullableReferenceTypeAnalyzer(), new NullableReferenceTypeCodeFixProvider(), code, true);

            Console.Write(processedCode.Replace(uniqueComment, ""));

            return(0);
        }