Esempio n. 1
0
        private List <MyShape> parseStringDataToListShapeObject(string data)
        {
            List <MyShape> myShapes  = new List <MyShape>();
            string         firstWord = null;

            string[] listShape = data.Split('\n');
            for (int i = 0; i < listShape.Length; i++)
            {
                if (listShape[i] != "")
                {
                    firstWord = listShape[i].Substring(0, listShape[i].IndexOf(" "));
                }
                switch (firstWord)
                {
                case "Line":
                    MyShape myLine = new MyLine();
                    myLine.Open(listShape[i]);
                    myShapes.Add(myLine);
                    break;

                case "Rectangle":
                    MyShape myRectangle = new MyRectangle();
                    myRectangle.Open(listShape[i]);
                    myShapes.Add(myRectangle);
                    break;

                case "Circle":
                    MyShape myCircle = new MyCircle();
                    myCircle.Open(listShape[i]);
                    myShapes.Add(myCircle);
                    break;

                case "Ellipse":
                    MyShape myEllipse = new MyEllipse();
                    myEllipse.Open(listShape[i]);
                    myShapes.Add(myEllipse);
                    break;

                case "Polygon":
                    MyShape myPolygon = new MyPolygon();
                    myPolygon.Open(listShape[i]);
                    myShapes.Add(myPolygon);
                    break;

                case "Bezier":
                    MyShape myBezier = new MyBezier();
                    myBezier.Open(listShape[i]);
                    myShapes.Add(myBezier);
                    break;

                case "Polyline":
                    MyShape myPolyline = new MyPolyline();
                    myPolyline.Open(listShape[i]);
                    myShapes.Add(myPolyline);
                    break;
                }
                firstWord = "";
            }
            return(myShapes);
        }