Exemplo n.º 1
0
        private static XElement WriteElement(PlistElement el)
        {
            if (el is PlistElementBoolean)
            {
                return(new XElement((XName)(!(el as PlistElementBoolean).value ? "false" : "true")));
            }
            if (el is PlistElementInteger)
            {
                return(new XElement((XName)"integer", (object)(el as PlistElementInteger).value.ToString()));
            }
            if (el is PlistElementString)
            {
                return(new XElement((XName)"string", (object)(el as PlistElementString).value));
            }
            if (el is PlistElementDict)
            {
                PlistElementDict plistElementDict = el as PlistElementDict;
                XElement         xelement1        = new XElement((XName)"dict");
                foreach (KeyValuePair <string, PlistElement> keyValuePair in (IEnumerable <KeyValuePair <string, PlistElement> >)plistElementDict.values)
                {
                    XElement xelement2 = new XElement((XName)"key", (object)keyValuePair.Key);
                    XElement xelement3 = PlistDocument.WriteElement(keyValuePair.Value);
                    if (xelement3 != null)
                    {
                        xelement1.Add((object)xelement2);
                        xelement1.Add((object)xelement3);
                    }
                }
                return(xelement1);
            }
            if (!(el is PlistElementArray))
            {
                return((XElement)null);
            }
            PlistElementArray plistElementArray = el as PlistElementArray;
            XElement          xelement4         = new XElement((XName)"array");

            foreach (PlistElement el1 in plistElementArray.values)
            {
                XElement xelement1 = PlistDocument.WriteElement(el1);
                if (xelement1 != null)
                {
                    xelement4.Add((object)xelement1);
                }
            }
            return(xelement4);
        }
Exemplo n.º 2
0
        private static PlistElement ReadElement(XElement xml)
        {
            switch (xml.Name.LocalName)
            {
            case "dict":
                List <XElement>  list1            = xml.Elements().ToList <XElement>();
                PlistElementDict plistElementDict = new PlistElementDict();
                if (list1.Count % 2 == 1)
                {
                    throw new Exception("Malformed plist file");
                }
                for (int index1 = 0; index1 < list1.Count - 1; ++index1)
                {
                    if (list1[index1].Name != (XName)"key")
                    {
                        throw new Exception("Malformed plist file");
                    }
                    string       index2       = PlistDocument.GetText(list1[index1]).Trim();
                    PlistElement plistElement = PlistDocument.ReadElement(list1[index1 + 1]);
                    if ((object)plistElement != null)
                    {
                        ++index1;
                        plistElementDict[index2] = plistElement;
                    }
                }
                return((PlistElement)plistElementDict);

            case "array":
                List <XElement>   list2             = xml.Elements().ToList <XElement>();
                PlistElementArray plistElementArray = new PlistElementArray();
                foreach (XElement xml1 in list2)
                {
                    PlistElement plistElement = PlistDocument.ReadElement(xml1);
                    if ((object)plistElement != null)
                    {
                        plistElementArray.values.Add(plistElement);
                    }
                }
                return((PlistElement)plistElementArray);

            case "string":
                return((PlistElement) new PlistElementString(PlistDocument.GetText(xml)));

            case "integer":
                int result;
                if (int.TryParse(PlistDocument.GetText(xml), out result))
                {
                    return((PlistElement) new PlistElementInteger(result));
                }
                return((PlistElement)null);

            case "true":
                return((PlistElement) new PlistElementBoolean(true));

            case "false":
                return((PlistElement) new PlistElementBoolean(false));

            default:
                return((PlistElement)null);
            }
        }