Ejemplo n.º 1
0
        public static RowFilter ReadXml(XmlReader reader)
        {
            var rowFilter = new RowFilter();

            rowFilter.Text = reader.GetAttribute("text");
            if (!string.IsNullOrEmpty(rowFilter.Text))
            {
                rowFilter.CaseSensitive = reader.GetAttribute("caseSensitive") != null;
            }
            if (reader.IsEmptyElement)
            {
                reader.Read();
                return(rowFilter);
            }
            reader.Read();
            var columnFilters = new List <ColumnFilter>();
            var columnSorts   = new List <ColumnSort>();

            while (true)
            {
                if (reader.IsStartElement("columnFilter"))
                {
                    var columnFilter = new ColumnFilter(new ColumnId(reader.GetAttribute("column")), FilterPredicate.ReadXml(reader));
                    if (reader.IsEmptyElement)
                    {
                        reader.Read();
                    }
                    else
                    {
                        reader.Read();
                        reader.ReadEndElement();
                    }
                    columnFilters.Add(columnFilter);
                }
                else if (reader.IsStartElement("columnSort"))
                {
                    var direction = Equals(SORT_DESC, reader.GetAttribute("direction"))
                        ? ListSortDirection.Descending
                        : ListSortDirection.Ascending;
                    var columnSort = new ColumnSort(new ColumnId(reader.GetAttribute("column")), direction);
                    columnSorts.Add(columnSort);
                    if (reader.IsEmptyElement)
                    {
                        reader.Read();
                    }
                    else
                    {
                        reader.Read();
                        reader.ReadEndElement();
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.ReadEndElement();
                    break;
                }
                else
                {
                    reader.Read();
                }
            }
            rowFilter.ColumnFilters = ImmutableList.ValueOf(columnFilters);
            rowFilter.ColumnSorts   = ImmutableList.ValueOf(columnSorts);
            return(rowFilter);
        }