Beispiel #1
0
    public static void process(XamlOptions options, string input)
    {
        if (!input.EndsWith(".xaml"))
        {
            Console.WriteLine("Input filenames must end in .xaml");
            return;
        }
        if (Environment.Version.Major < 2 && options.Partial)
        {
            Console.WriteLine("This runtime version does not support partial classes");
            return;
        }
        if (options.OutputFile == null)
        {
            options.OutputFile = input + ".out";
        }
        ICodeGenerator generator = getGenerator(options.OutputLanguage);
        XmlTextReader  xr        = new XmlTextReader(input);

        try {
            string     result = ParserToCode.Parse(xr, generator, options.Partial);
            TextWriter tw     = new StreamWriter(options.OutputFile);
            tw.Write(result);
            tw.Close();
        }
        catch (Exception ex) {
            Console.WriteLine("Line " + xr.LineNumber + ", Column " + xr.LinePosition);
            throw ex;
        }
    }
Beispiel #2
0
        private void compare(string expected, bool isPartial)
        {
            int            i, j;
            ICodeGenerator generator = (new Microsoft.CSharp.CSharpCodeProvider()).CreateGenerator();
            string         mapping   = "<?Mapping ClrNamespace=\"Xaml.TestVocab.Console\" Assembly=\"./TestVocab.dll\" XmlNamespace=\"console\" ?>\n";
            string         w         = ParserToCode.Parse(new XmlTextReader(new StringReader(mapping + code)), generator, isPartial);

            string[] actualLines = w.ToString().Split('\n');
            for (i = 0; i < actualLines.Length; i++)
            {
                // set commented-out lines to null
                if (actualLines[i].StartsWith("//"))
                {
                    actualLines[i] = null;
                    continue;
                }

                // set lines containing only whitespace to null
                j = 0;
                while (j < actualLines[i].Length &&
                       Char.IsWhiteSpace(actualLines[i][j]))
                {
                    j++;
                }
                if (j == actualLines[i].Length)
                {
                    actualLines[i] = null;
                    continue;
                }
            }
            // shift all null elements to end of list and join all non-null elements
            j = 0;
            for (i = 0; i < actualLines.Length; i++)
            {
                if (actualLines[i] != null)
                {
                    actualLines[j++] = actualLines[i];
                }
            }
            string actual = String.Join("\n", actualLines, 0, j);

            string[] expectedLines = expected.Split('\n');
            for (i = 0; i < expectedLines.Length; i++)
            {
                expectedLines[i] = replaceTabsAtLineStart(expectedLines[i]);
            }
            expected = String.Join("\n", expectedLines);

            if (expected != actual)
            {
                Debug.WriteLine("FULL EXPECTED:");
                Debug.WriteLine(expected);
                Debug.WriteLine("===============================================");
                Debug.WriteLine("FULL ACTUAL:");
                Debug.WriteLine(actual);
            }
            Assert.AreEqual(expected, actual);
        }