예제 #1
0
        public static Target ReadXml(string targetText)
        {
            if (String.IsNullOrEmpty(targetText))
            {
                return(null);
            }
            if (_settings == null)
            {
                _settings                  = new XmlReaderSettings();
                _settings.CloseInput       = true;
                _settings.ConformanceLevel = ConformanceLevel.Fragment;
            }

            Target target = null;

            StringReader textReader = new StringReader(targetText);
            XmlReader    reader     = XmlReader.Create(textReader, _settings);

            reader.MoveToContent();
            target = TargetsReader.ReadTarget(reader);
            reader.Close();

            return(target);
        }
예제 #2
0
        protected override void OnReadXml(XmlReader reader)
        {
            base.OnReadXml(reader);

            // This reads only the target node...
            if (!String.Equals(reader.Name, "EnumerationTarget",
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            elements = new List <MemberTarget>();

            XmlNodeType nodeType = XmlNodeType.None;

            while (reader.Read())
            {
                nodeType = reader.NodeType;

                if (nodeType == XmlNodeType.Element)
                {
                    // Read the base contents in...
                    if (String.Equals(reader.Name, "TypeTarget",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        base.OnReadXml(reader);
                    }
                    else if (String.Equals(reader.Name, "Elements",
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        while (reader.Read())
                        {
                            nodeType = reader.NodeType;

                            if (nodeType == XmlNodeType.Element)
                            {
                                if (reader.Name.IndexOf("Target", 0, StringComparison.OrdinalIgnoreCase) >= 0)
                                {
                                    MemberTarget target = TargetsReader.ReadMemberTarget(reader);
                                    if (target != null)
                                    {
                                        elements.Add(target);
                                    }
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement)
                            {
                                if (String.Equals(reader.Name, "Elements",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, "EnumerationTarget",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }