locked
How can i create List of Maps of each Map class ? RRS feed

  • Question

  • using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Xml.Linq;
    using UnityEngine;
    
    public class SvgMapReader
    {    
        public void ParseMaps()
        {
            StreamWriter w = new StreamWriter(@"c:\temp\Rectangles.txt");
            //XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawingtest.svg");
            XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawing.svg");
    
            Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => new Map()
            {
                style = Map.GetStyle((string)x.Attribute("style")),
                id = (string)x.Attribute("id"),
                width = (double)x.Attribute("width"),
                height = (double)x.Attribute("height"),
                x = (double?)x.Attribute("x"),
                y = (double?)x.Attribute("y"),
                matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
            }).ToList();
    
            for (int i = 0; i < Map.Rectangles.Count; i++)
            {
                if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                {
                    var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                    List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                  .Cast<Match>()
                  .SelectMany(m => m.Groups["num"]
                                    .Captures
                                    .Cast<Capture>()
                                    .Select(c => c.Value))
                  .Select(double.Parse)
                  .ToList();
    
                    Map.Rectangles[i].degree = values[0];//degree;
                }
    
                w.WriteLine("Rectangle" + i);
                w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                w.WriteLine("X ===> " + Map.Rectangles[i].x);
                w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                w.WriteLine(" ");
            }
            w.Close();
        }
    
        public float FindDegree(double a, double b)
        {
            float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
            if (value < 0) value += 360f;
    
            return value;
        }
    
        public class Map
        {
            public static List<Map> Rectangles { get; set; }
            public Dictionary<string, string> style { get; set; }
            public string id { get; set; }
            public double width { get; set; }
            public double height { get; set; }
            public double? x { get; set; }
            public double? y { get; set; }
            public string matrix { get; set; }
            public double degree { get; set; }
    
            public static Dictionary<string, string> GetStyle(string styles)
            {
                string pattern = @"(?'name'[^:]+):(?'value'.*)";
                string[] splitArray = styles.Split(new char[] { ';' });
                Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                    .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                    .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                return style;
            }
        }
    }

    In the end i see in the List Rectangles that it have 133 items. But each item is a rectangle.

    What i want to do is to create another List and call it Maps. This List should contain each Map and each Map should have Rectangles and when i will look with a break point on each Map Rectangles List it should show me for example on the first item:

    [0] {Rectangle 1}
    [1] {Rectangle 2} 

    But now it show me each item name like this:

    [0] {SvgMapReader+Map}
    [1] {SvgMapReader+Map}

    So in the end what i want is to have List of Maps and the list should be build like this example: The first item will be:

    [0] {Map 1}

    Then inside Map 1:

    [0] {Rectangles}
    [1] {Triangles}
    [2] {Boxes}
    ....

    And inside Rectangles:

    [0] {Rectangle 1}
    [1] {Rectangle 2}
    ....

    Same inside Triangles or boxes....

    This is how the Maps List should be as hierarchy.

    Sunday, July 2, 2017 6:05 AM

Answers

  • Hi Chocolade1972,

    >>The first item will be:

    [0] {Map 1}

    Then inside Map 1:

    [0] {Rectangles}

    [1] {Triangles}

    [2] {Boxes}

    ....

    And inside Rectangles:

    [0] {Rectangle 1}

    [1] {Rectangle 2}

    ....

    Same inside Triangles or boxes....

    I mean you  could  create differences Properties in the Map Class and define different class inheriting the same class, as follows.

        class Map
        {
            public Rectangle Rectangles { get; set; }
            public Triangle Triangles { set; get; }
            …
        }
        public class Shape
        {
            ...
        }
        public class Triangle : Shape
        {
            …
        }
        public class Rectangle : Shape
        {
    …
        }
    

    You could create a different object according to x.Name.LocalName=="rect" orx.Name.LocalName=="Triangle". 

    >>When using a break point on the Rectangles now I see 133 items but the names and everything is just like before and also all of them each rectangle values is 0 or null.  

    I only tested a .svg file on my side  and it is not 0 or null. You could check whether one of your 133 items can convert to the specified type about your 133 items. 

    Here is all my code for your reference.

    class Program
        {
            static void Main(string[] args)
            {
                SvgMapReader smr = new SvgMapReader();
                smr.ParseMaps();
                Console.ReadKey();
            }
        }
       public class SvgMapReader
        {
            public void ParseMaps()
            {
                StreamWriter w = new StreamWriter(@"C:\Users\v-jianpw\Desktop\svg.txt");
                //XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawingtest.svg");
                XDocument document = XDocument.Load(@"C:\Users\v-jianpw\Desktop\rect4.svg");
                //List<Shape> list =
                Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangle ()
                {
                    style = Shape.GetStyle((string)x.Attribute("style")),
                    id = (string)x.Attribute("id"),
                    width = (double)x.Attribute("width"),
                    height = (double)x.Attribute("height"),
                    x = (double?)x.Attribute("x"),
                    y = (double?)x.Attribute("y"),
                    matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
                })).ToList();
    
                for (int i = 0; i < Map.Rectangles.Count; i++)
                {
                    if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                    {
                        var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                        List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                      .Cast<Match>()
                      .SelectMany(m => m.Groups["num"]
                                        .Captures
                                        .Cast<Capture>()
                                        .Select(c => c.Value))
                      .Select(double.Parse)
                      .ToList();
    
                        Map.Rectangles[i].degree = values[0];//degree;
                    }
    
                    w.WriteLine("Rectangle " + i);
                    w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                    w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                    w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                    w.WriteLine("X ===> " + Map.Rectangles[i].x);
                    w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                    w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                    w.WriteLine(" ");
                }
                w.Close();
            }
    
            public float FindDegree(double a, double b)
            {
                float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
                if (value < 0) value += 360f;
    
                return value;
            }
    
            public class Shape
            {
                public Dictionary<string, string> style { get; set; }
                public string id { get; set; }
                public double width { get; set; }
                public double height { get; set; }
                public double? x { get; set; }
                public double? y { get; set; }
                public string matrix { get; set; }
                public double degree { get; set; }
    
                public static Dictionary<string, string> GetStyle(string styles)
                {
                    string pattern = @"(?'name'[^:]+):(?'value'.*)";
                    string[] splitArray = styles.Split(new char[] { ';' });
                    Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                        .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                        .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                    return style;
                }
            }
            public class Map
            {
                public static List<Shape> Rectangles { get; set; }
                public static List<Shape> Triangles { get; set; }
            }
            public class Triangle : Shape
            {
           
            }
            public class Rectangle : Shape
            {
            }
    
        }
    

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Chocolade1972 Friday, July 14, 2017 2:44 AM
    Friday, July 14, 2017 2:33 AM

All replies

  • Hi Chocolade1972,

    Thank you for posting the problem.

    I think you would like to read different .svg file, show different Map according to graphics.

    But the Map.Rectangles restore an object of Map. So When you  look with a break point each Map Rectangle list, it shows item name  like the picture.

    If you want that the List restores different map object, you could create one or more class inheriting the Map Class. You can choose to create different class objects based on the .svg file content features.

    Please try the following code.

            public class SvgMapReader 
        {
            public void ParseMaps()
            {
                StreamWriter w = new StreamWriter(@"C:\Users\WangJianPing\Desktop\svg.txt");
                XDocument document = XDocument.Load(@"C:\Users\WangJianPing\Desktop\rect4.svg");
                Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangles()
                {
                    style = Shape.GetStyle((string)x.Attribute("style")),
                    id = (string)x.Attribute("id"),
                    width = (double)x.Attribute("width"),
                    height = (double)x.Attribute("height"),
                    x = (double?)x.Attribute("x"),
                    y = (double?)x.Attribute("y"),
                    matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
                })).ToList();
    
                for (int i = 0; i < Map.Rectangles.Count; i++)
                {
                    if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                    {
                        var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                        List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                      .Cast<Match>()
                      .SelectMany(m => m.Groups["num"]
                                        .Captures
                                        .Cast<Capture>()
                                        .Select(c => c.Value))
                      .Select(double.Parse)
                      .ToList();
    
                        Map.Rectangles[i].degree = values[0];//degree;
                    }
    
                    w.WriteLine("Rectangle " + i);
                    w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                    w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                    w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                    w.WriteLine("X ===> " + Map.Rectangles[i].x);
                    w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                    w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                    w.WriteLine(" ");
                }
                w.Close();
            }
    
            public float FindDegree(double a, double b)
            {
                float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
                if (value < 0) value += 360f;
    
                return value;
            }
    
            public class Shape
            {
                public Dictionary<string, string> style { get; set; }
                public string id { get; set; }
                public double width { get; set; }
                public double height { get; set; }
                public double? x { get; set; }
                public double? y { get; set; }
                public string matrix { get; set; }
                public double degree { get; set; }
    
                public static Dictionary<string, string> GetStyle(string styles)
                {
                    string pattern = @"(?'name'[^:]+):(?'value'.*)";
                    string[] splitArray = styles.Split(new char[] { ';' });
                    Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                        .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                        .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                    return style;
                }
            }
            public class Map
            {
                public static List<Shape> Rectangles { get; set; }
    
            }
        }
        public class Triangles : Shape
        {
    
    
        }
        public class Rectangles : Shape
        {
    
        }
    
    Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape) ( new Rectangles()
    

    For the above code, you could create a different object according to the value of  x.Name.LocalName == "rect" or =="triangles".

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 6, 2017 2:36 AM
  • Hi Chocolade1972,

    Thank you for posting the problem.

    I think you would like to read different .svg file, show different Map according to graphics.

    But the Map.Rectangles restore an object of Map. So When you  look with a break point each Map Rectangle list, it shows item name  like the picture.

    If you want that the List restores different map object, you could create one or more class inheriting the Map Class. You can choose to create different class objects based on the .svg file content features.

    Please try the following code.

            public class SvgMapReader 
        {
            public void ParseMaps()
            {
                StreamWriter w = new StreamWriter(@"C:\Users\WangJianPing\Desktop\svg.txt");
                XDocument document = XDocument.Load(@"C:\Users\WangJianPing\Desktop\rect4.svg");
                Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangles()
                {
                    style = Shape.GetStyle((string)x.Attribute("style")),
                    id = (string)x.Attribute("id"),
                    width = (double)x.Attribute("width"),
                    height = (double)x.Attribute("height"),
                    x = (double?)x.Attribute("x"),
                    y = (double?)x.Attribute("y"),
                    matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
                })).ToList();
    
                for (int i = 0; i < Map.Rectangles.Count; i++)
                {
                    if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                    {
                        var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                        List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                      .Cast<Match>()
                      .SelectMany(m => m.Groups["num"]
                                        .Captures
                                        .Cast<Capture>()
                                        .Select(c => c.Value))
                      .Select(double.Parse)
                      .ToList();
    
                        Map.Rectangles[i].degree = values[0];//degree;
                    }
    
                    w.WriteLine("Rectangle " + i);
                    w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                    w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                    w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                    w.WriteLine("X ===> " + Map.Rectangles[i].x);
                    w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                    w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                    w.WriteLine(" ");
                }
                w.Close();
            }
    
            public float FindDegree(double a, double b)
            {
                float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
                if (value < 0) value += 360f;
    
                return value;
            }
    
            public class Shape
            {
                public Dictionary<string, string> style { get; set; }
                public string id { get; set; }
                public double width { get; set; }
                public double height { get; set; }
                public double? x { get; set; }
                public double? y { get; set; }
                public string matrix { get; set; }
                public double degree { get; set; }
    
                public static Dictionary<string, string> GetStyle(string styles)
                {
                    string pattern = @"(?'name'[^:]+):(?'value'.*)";
                    string[] splitArray = styles.Split(new char[] { ';' });
                    Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                        .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                        .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                    return style;
                }
            }
            public class Map
            {
                public static List<Shape> Rectangles { get; set; }
    
            }
        }
        public class Triangles : Shape
        {
    
    
        }
        public class Rectangles : Shape
        {
    
        }
    
    Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape) ( new Rectangles()

    For the above code, you could create a different object according to the value of  x.Name.LocalName == "rect" or =="triangles".

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Not working yet.

    First i had to move this line and put it in some method:

    Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape) ( new Rectangles()

    So i put it in the end in the bottom of ParseMaps method. And also i had to add in the end of the line ToList()

    Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x =>

    (Shape)(new Rectangles())).ToList();


    This is the complete class after the changes:

    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Xml.Linq;
    using UnityEngine;
    
    public class SvgMapReader
    {
        public void ParseMaps()
        {
            StreamWriter w = new StreamWriter(@"c:\temp\Rectangles.txt");
            XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawing.svg");
    
            Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangles()
            {
                style = Shape.GetStyle((string)x.Attribute("style")),
                id = (string)x.Attribute("id"),
                width = (double)x.Attribute("width"),
                height = (double)x.Attribute("height"),
                x = (double?)x.Attribute("x"),
                y = (double?)x.Attribute("y"),
                matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
            })).ToList();
    
            for (int i = 0; i < Map.Rectangles.Count; i++)
            {
                if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                {
                    var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                    List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                  .Cast<Match>()
                  .SelectMany(m => m.Groups["num"]
                                    .Captures
                                    .Cast<Capture>()
                                    .Select(c => c.Value))
                  .Select(double.Parse)
                  .ToList();
    
                    //Map.Rectangles[i].degree = values[0];//degree;
                }
    
                w.WriteLine("Rectangle " + i);
                w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                w.WriteLine("X ===> " + Map.Rectangles[i].x);
                w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                w.WriteLine(" ");
            }
            w.Close();
    
            Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangles())).ToList();
        }
    
        public float FindDegree(double a, double b)
        {
            float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
            if (value < 0) value += 360f;
    
            return value;
        }
    
        public class Shape
        {
            public Dictionary<string, string> style { get; set; }
            public string id { get; set; }
            public double width { get; set; }
            public double height { get; set; }
            public double? x { get; set; }
            public double? y { get; set; }
            public string matrix { get; set; }
            public double degree { get; set; }
    
            public static Dictionary<string, string> GetStyle(string styles)
            {
                string pattern = @"(?'name'[^:]+):(?'value'.*)";
                string[] splitArray = styles.Split(new char[] { ';' });
                Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                    .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                    .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                return style;
            }
        }
        public class Map
        {
            public static List<Shape> Rectangles { get; set; }
    
        }
    
        public class Triangles : Shape
        {
    
    
        }
        public class Rectangles : Shape
        {
    
        }
    
    }
    
    

    And this is how i'm using it:

    SvgMapReader mapreader = new SvgMapReader();
            mapreader.ParseMaps();
    
            int test = SvgMapReader.Map.Rectangles.Count;

    When using a break point on the Rectangles now i see 133 items but the names and everything is just like before and also all of them each rectangle values is 0 or null. 

    And if i'm trying to use my old code as before the rectangles have values and everything.

    Maybe i did something wrong but it's not working yet.

    Sunday, July 9, 2017 2:42 AM
  • Hi Chocolade1972,

    >>The first item will be:

    [0] {Map 1}

    Then inside Map 1:

    [0] {Rectangles}

    [1] {Triangles}

    [2] {Boxes}

    ....

    And inside Rectangles:

    [0] {Rectangle 1}

    [1] {Rectangle 2}

    ....

    Same inside Triangles or boxes....

    I mean you  could  create differences Properties in the Map Class and define different class inheriting the same class, as follows.

        class Map
        {
            public Rectangle Rectangles { get; set; }
            public Triangle Triangles { set; get; }
            …
        }
        public class Shape
        {
            ...
        }
        public class Triangle : Shape
        {
            …
        }
        public class Rectangle : Shape
        {
    …
        }
    

    You could create a different object according to x.Name.LocalName=="rect" orx.Name.LocalName=="Triangle". 

    >>When using a break point on the Rectangles now I see 133 items but the names and everything is just like before and also all of them each rectangle values is 0 or null.  

    I only tested a .svg file on my side  and it is not 0 or null. You could check whether one of your 133 items can convert to the specified type about your 133 items. 

    Here is all my code for your reference.

    class Program
        {
            static void Main(string[] args)
            {
                SvgMapReader smr = new SvgMapReader();
                smr.ParseMaps();
                Console.ReadKey();
            }
        }
       public class SvgMapReader
        {
            public void ParseMaps()
            {
                StreamWriter w = new StreamWriter(@"C:\Users\v-jianpw\Desktop\svg.txt");
                //XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawingtest.svg");
                XDocument document = XDocument.Load(@"C:\Users\v-jianpw\Desktop\rect4.svg");
                //List<Shape> list =
                Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => (Shape)(new Rectangle ()
                {
                    style = Shape.GetStyle((string)x.Attribute("style")),
                    id = (string)x.Attribute("id"),
                    width = (double)x.Attribute("width"),
                    height = (double)x.Attribute("height"),
                    x = (double?)x.Attribute("x"),
                    y = (double?)x.Attribute("y"),
                    matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
                })).ToList();
    
                for (int i = 0; i < Map.Rectangles.Count; i++)
                {
                    if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
                    {
                        var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
                        List<double> values = regex.Matches(Map.Rectangles[i].matrix)
                      .Cast<Match>()
                      .SelectMany(m => m.Groups["num"]
                                        .Captures
                                        .Cast<Capture>()
                                        .Select(c => c.Value))
                      .Select(double.Parse)
                      .ToList();
    
                        Map.Rectangles[i].degree = values[0];//degree;
                    }
    
                    w.WriteLine("Rectangle " + i);
                    w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
                    w.WriteLine("Height ===> " + Map.Rectangles[i].height);
                    w.WriteLine("Width ===> " + Map.Rectangles[i].width);
                    w.WriteLine("X ===> " + Map.Rectangles[i].x);
                    w.WriteLine("Y ===> " + Map.Rectangles[i].y);
                    w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
                    w.WriteLine(" ");
                }
                w.Close();
            }
    
            public float FindDegree(double a, double b)
            {
                float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
                if (value < 0) value += 360f;
    
                return value;
            }
    
            public class Shape
            {
                public Dictionary<string, string> style { get; set; }
                public string id { get; set; }
                public double width { get; set; }
                public double height { get; set; }
                public double? x { get; set; }
                public double? y { get; set; }
                public string matrix { get; set; }
                public double degree { get; set; }
    
                public static Dictionary<string, string> GetStyle(string styles)
                {
                    string pattern = @"(?'name'[^:]+):(?'value'.*)";
                    string[] splitArray = styles.Split(new char[] { ';' });
                    Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
                        .GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
                        .ToDictionary(x => x.Key, y => y.FirstOrDefault());
                    return style;
                }
            }
            public class Map
            {
                public static List<Shape> Rectangles { get; set; }
                public static List<Shape> Triangles { get; set; }
            }
            public class Triangle : Shape
            {
           
            }
            public class Rectangle : Shape
            {
            }
    
        }
    

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Chocolade1972 Friday, July 14, 2017 2:44 AM
    Friday, July 14, 2017 2:33 AM