Пример #1
0
        private void XamlGen_click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog oDiag = new OpenFileDialog();

            oDiag.Title  = "Select C# File";
            oDiag.Filter = "C# Files|*.cs|All Files|*.*";

            if (oDiag.ShowDialog() == true)
            {
                XamlGenerator.ProcessFileForGrid(oDiag.FileName);
            }
        }
Пример #2
0
        public static void ProcessFileForGrid(string path)
        {
            int           row = 0;
            StringBuilder sb  = new StringBuilder();

            using (StreamReader sr = new StreamReader(path))
            {
                //public double NetworkPort
                string sLine = string.Empty;
                while (sLine != null)
                {
                    sLine = sr.ReadLine();
                    if (sLine != null)
                    {
                        string wrkLine = sLine.Replace("\t", string.Empty).Trim();
                        if (wrkLine.StartsWith("public "))
                        {
                            //count spaces.  More than 2, skip
                            int spaceC = 0;
                            for (int i = 0; i < wrkLine.Length; i++)
                            {
                                if (wrkLine[i] == ' ')
                                {
                                    spaceC++;
                                }
                            }
                            if (spaceC == 2)
                            {
                                string wrk2 = wrkLine.Substring(wrkLine.IndexOf(' ')).Trim();
                                int    i    = wrk2.IndexOf(' ');
                                if (i > -1)
                                {
                                    string type         = wrk2.Substring(0, i).Trim();
                                    string propertyName = wrk2.Substring(i).Trim();


                                    sb.AppendLine(XamlGenerator.GetGridSegment(GetLabelContent(propertyName), propertyName, type, row++, 0));
                                }
                            }
                        }
                    }
                }
            }
            StringBuilder ut = new StringBuilder();

            ut.AppendLine("<ScrollViewer VerticalScrollBarVisibility=\"Auto\">");
            ut.AppendLine("<Grid>");
            ut.AppendLine("<Grid.ColumnDefinitions>");
            ut.AppendLine("<ColumnDefinition />");
            ut.AppendLine("<ColumnDefinition />");
            ut.AppendLine("</Grid.ColumnDefinitions>");
            ut.AppendLine("<Grid.RowDefinitions>");
            for (int i = 0; i <= row; i++)
            {
                ut.AppendLine("<RowDefinition />");
            }
            ut.AppendLine("</Grid.RowDefinitions>");
            ut.AppendLine(sb.ToString());
            ut.AppendLine("</Grid>");
            ut.AppendLine("</ScrollViewer>");
            string XamlFile = System.IO.Path.GetTempFileName();

            using (StreamWriter sw = new StreamWriter(XamlFile))
            {
                sw.WriteLine(ut.ToString());
            }
            Process.Start("Notepad.exe", string.Format("\"{0}\"", XamlFile));
        }