GetText() private static method

private static GetText ( System.Xml.Linq.XElement xml ) : string
xml System.Xml.Linq.XElement
return string
Beispiel #1
0
        private static PlistElement ReadElement(XElement xml)
        {
            string localName = xml.Name.LocalName;

            if (localName != null)
            {
                Dictionary <string, int> types = new Dictionary <string, int>(8)
                {
                    {
                        "dict",
                        0
                    },
                    {
                        "array",
                        1
                    },
                    {
                        "string",
                        2
                    },
                    {
                        "integer",
                        3
                    },
                    {
                        "real",
                        4
                    },
                    {
                        "date",
                        5
                    },
                    {
                        "true",
                        6
                    },
                    {
                        "false",
                        7
                    }
                };

                int num = 0;
                if (types.TryGetValue(localName, out num))
                {
                    switch (num)
                    {
                    case 0:
                        List <XElement>  list1            = Enumerable.ToList <XElement>(xml.Elements());
                        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. Found '" + (object)list1[index1].Name + "' where 'key' was expected.");
                            }
                            string       index2       = PlistDocument.GetText(list1[index1]).Trim();
                            PlistElement plistElement = PlistDocument.ReadElement(list1[index1 + 1]);
                            if (plistElement != null)
                            {
                                ++index1;
                                plistElementDict[index2] = plistElement;
                            }
                        }
                        return((PlistElement)plistElementDict);

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

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

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

                    case 4:
                        float result2;
                        if (float.TryParse(PlistDocument.GetText(xml), out result2))
                        {
                            return((PlistElement) new PlistElementReal(result2));
                        }
                        return((PlistElement)null);

                    case 5:
                        DateTime result3;
                        if (DateTime.TryParse(PlistDocument.GetText(xml), out result3))
                        {
                            return((PlistElement) new PlistElementDate(result3.ToUniversalTime()));
                        }
                        return((PlistElement)null);

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

                    case 7:
                        return((PlistElement) new PlistElementBoolean(false));
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        private static PlistElement ReadElement(XElement xml)
        {
            string localName = xml.Name.LocalName;
            // ISSUE: reference to a compiler-generated method
            uint stringHash = PrivateImplementationDetails.ComputeStringHash(localName);

            if (stringHash <= 1303515621U)
            {
                if (stringHash <= 398550328U)
                {
                    if ((int)stringHash != 184981848)
                    {
                        if ((int)stringHash == 398550328 && localName == "string")
                        {
                            return((PlistElement) new PlistElementString(PlistDocument.GetText(xml)));
                        }
                    }
                    else if (localName == "false")
                    {
                        return((PlistElement) new PlistElementBoolean(false));
                    }
                }
                else if ((int)stringHash != 1278716217)
                {
                    if ((int)stringHash == 1303515621 && localName == "true")
                    {
                        return((PlistElement) new PlistElementBoolean(true));
                    }
                }
                else if (localName == "dict")
                {
                    List <XElement>  list             = Enumerable.ToList <XElement>(xml.Elements());
                    PlistElementDict plistElementDict = new PlistElementDict();
                    if (list.Count % 2 == 1)
                    {
                        throw new Exception("Malformed plist file");
                    }
                    for (int index1 = 0; index1 < list.Count - 1; ++index1)
                    {
                        if (list[index1].Name != (XName)"key")
                        {
                            throw new Exception("Malformed plist file. Found '" + (object)list[index1].Name + "' where 'key' was expected.");
                        }
                        string       index2       = PlistDocument.GetText(list[index1]).Trim();
                        PlistElement plistElement = PlistDocument.ReadElement(list[index1 + 1]);
                        if (plistElement != null)
                        {
                            ++index1;
                            plistElementDict[index2] = plistElement;
                        }
                    }
                    return((PlistElement)plistElementDict);
                }
            }
            else if (stringHash <= 3218261061U)
            {
                if ((int)stringHash != -1973899994)
                {
                    int result;
                    if ((int)stringHash == -1076706235 && localName == "integer" && int.TryParse(PlistDocument.GetText(xml), out result))
                    {
                        return((PlistElement) new PlistElementInteger(result));
                    }
                }
                else if (localName == "array")
                {
                    List <XElement>   list = Enumerable.ToList <XElement>(xml.Elements());
                    PlistElementArray plistElementArray = new PlistElementArray();
                    foreach (XElement xml1 in list)
                    {
                        PlistElement plistElement = PlistDocument.ReadElement(xml1);
                        if (plistElement != null)
                        {
                            plistElementArray.values.Add(plistElement);
                        }
                    }
                    return((PlistElement)plistElementArray);
                }
            }
            else if ((int)stringHash != -730669991)
            {
                float result;
                if ((int)stringHash == -689983395 && localName == "real" && float.TryParse(PlistDocument.GetText(xml), out result))
                {
                    return((PlistElement) new PlistElementReal(result));
                }
            }
            else
            {
                DateTime result;
                if (localName == "date" && DateTime.TryParse(PlistDocument.GetText(xml), out result))
                {
                    return((PlistElement) new PlistElementDate(result.ToUniversalTime()));
                }
            }
            return((PlistElement)null);
        }