Пример #1
0
        private void ParseDictionary(PListDictionary dict, IEnumerable <XElement> elements)
        {
            for (int i = 0; i < elements.Count(); i += 2)
            {
                XElement key = elements.ElementAt(i);
                XElement val = elements.ElementAt(i + 1);

                PListElement element = CreateElement(key, val);

                if (element == null)
                {
                    throw new InvalidOperationException("Key " + key.Value + " has no value");
                }

                dict.Elements.Add(key.Value, element);
            }
        }
Пример #2
0
 public void Add(PListElement element)
 {
     this.AddElement(element);
 }
Пример #3
0
 protected virtual void AddElement(PListElement element)
 {
     throw new InvalidOperationException("You cannot add a child element");
 }
Пример #4
0
        private PListElement CreateElement(XElement key, XElement val)
        {
            PListElement element = null;

            switch (val.Name.ToString())
            {
            case "data":
                if (key == null)
                {
                    element = new PListDataElement(val.Value);
                }
                else
                {
                    element = new PListDataElement(key.Value, val.Value);
                }
                break;

            case "string":
                if (key == null)
                {
                    element = new PListStringElement(val.Value);
                }
                else
                {
                    element = new PListStringElement(key.Value, val.Value);
                }
                break;

            case "integer":
                if (key == null)
                {
                    element = new PListIntegerElement(int.Parse(val.Value));
                }
                else
                {
                    element = new PListIntegerElement(key.Value, int.Parse(val.Value));
                }
                break;

            case "real":
                element = new PListRealElement(key.Value, float.Parse(val.Value));
                break;

            case "true":
                element = new PListBoolElement(key.Value, true);
                break;

            case "false":
                element = new PListBoolElement(key.Value, false);
                break;

            case "dict":
                if (key == null)
                {
                    element = new PListDictionary();
                }
                else
                {
                    element = new PListDictionary(key.Value);
                }
                ParseDictionary((PListDictionary)element, val.Elements());
                break;

            case "array":
                element = new PListArray(key.Value);
                ParseArray((PListArray)element, val.Elements());
                break;
            }

            return(element);
        }
Пример #5
0
 protected override void AddElement(PListElement element)
 {
     Elements.Add(element.Key, element);
 }