Exemple #1
0
    /// Main function for Example2
    public static void Main(String[] args)
    {
        // files to pass to AStyle
        String[] fileName =  { "AStyleDev/test-s/FileUtility.cs",
                               "AStyleDev/test-s/MainClass.cs" ,
                               "AStyleDev/test-s/StringParser.cs" ,
                             };

        // create an object
        AStyleInterface AStyle = new AStyleInterface();

        // set test values for the options
        AStyle.setTestOptions();

        // get Artistic Style version
        // does not need to terminate on an error
        String version = AStyle.GetVersion();
        if (version != String.Empty)
            Console.WriteLine ("Example2 C# - AStyle " + version);

        // process the files
        for (int i = 0; i < fileName.Length; i++)
        {   // get the text to format
            String filePath = GetProjectDirectory(fileName[i]);
            String textIn = GetText(filePath);

            // call the Artistic Style formatting function
            // does not need to terminate on an error
            String textOut = AStyle.FormatSource(textIn, fileName[i]);
            if (textOut == String.Empty)
            {   Console.WriteLine("Cannot format "  + filePath);
                continue;
            }

            // return the formatted text
            Console.WriteLine("Formatted " + fileName[i]);
            SetText(textOut, filePath);
        }

        return;
    }