예제 #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((ListDef.GetHashCode() * 397) ^ Columns.GetHashCode());
     }
 }
예제 #2
0
 public ListData(ListDef listDef, IEnumerable <ColumnData> columns)
 {
     ListDef = listDef;
     Columns = ImmutableList.ValueOf(columns);
     Init();
     RebuildIndex();
 }
예제 #3
0
 protected bool Equals(ListDef other)
 {
     return(base.Equals(other) &&
            Equals(Properties, other.Properties) &&
            string.Equals(IdProperty, other.IdProperty) &&
            string.Equals(DisplayProperty, other.DisplayProperty));
 }
예제 #4
0
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteStartElement(El.list_def);
     ListDef.WriteXml(writer);
     writer.WriteEndElement();
     foreach (var column in Columns)
     {
         writer.WriteElementString(El.column, column.ToPersistedString());
     }
 }
예제 #5
0
        public ListData ChangeListDef(ListDef newListDef, IDictionary <string, string> originalColumnNames)
        {
            if (RowCount == 0 || originalColumnNames != null && originalColumnNames.Count == 0)
            {
                return(new ListData(newListDef));
            }
            var newColumns = new List <ColumnData>();

            foreach (var annotationDef in newListDef.Properties)
            {
                string originalName;
                if (originalColumnNames == null)
                {
                    originalName = annotationDef.Name;
                }
                else
                {
                    if (!originalColumnNames.TryGetValue(annotationDef.Name, out originalName))
                    {
                        newColumns.Add(ColumnData.MakeColumnData(annotationDef).SetRowCount(RowCount));
                        continue;
                    }
                }
                int icolOrig          = FindColumnIndex(originalName);
                var origColumn        = Columns[icolOrig];
                var origAnnotationDef = ListDef.Properties[icolOrig];
                if (annotationDef.ValueType == origAnnotationDef.ValueType)
                {
                    newColumns.Add(origColumn);
                    continue;
                }
                var newColumn = ColumnData.MakeColumnData(annotationDef).SetRowCount(RowCount);
                for (int i = 0; i < RowCount; i++)
                {
                    var    origValue = origColumn.GetValue(i);
                    object newValue;
                    if (!TryChangeType(origValue, annotationDef.ValueType, out newValue))
                    {
                        throw CommonException.Create(
                                  ListExceptionDetail.InvalidValue(newListDef.Name, origAnnotationDef.Name, origValue));
                    }
                    if (newValue != null)
                    {
                        newColumn.SetValue(i, newValue);
                    }
                }
                newColumns.Add(newColumn);
            }
            return(new ListData(newListDef, newColumns));
        }
예제 #6
0
        public void ReadXml(XmlReader reader)
        {
            if (null != Columns)
            {
                throw new ReadOnlyException();
            }
            List <ColumnData> columns = new List <ColumnData>();

            if (reader.IsEmptyElement)
            {
                reader.ReadElementString(@"list_data");
                return;
            }
            reader.Read();
            while (true)
            {
                if (reader.IsStartElement(El.list_def))
                {
                    ListDef = ListDef.Deserialize(reader);
                }
                else if (reader.IsStartElement(El.column))
                {
                    string columnText = reader.ReadElementContentAsString();
                    if (columns.Count < ListDef.Properties.Count)
                    {
                        var annotationDef = ListDef.Properties[columns.Count];
                        columns.Add(ColumnData.MakeColumnData(annotationDef).SetPersistedString(columnText));
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.ReadEndElement();
                    break;
                }
                else
                {
                    reader.Skip();
                }
            }
            Columns = ImmutableList.ValueOf(columns);
            Init();
            RebuildIndex();
        }
예제 #7
0
 public ListData(ListDef listDef) : this(listDef, listDef.Properties.Select(ColumnData.MakeColumnData))
 {
 }
예제 #8
0
 protected bool Equals(ListData other)
 {
     return(ListDef.Equals(other.ListDef) && Columns.Equals(other.Columns));
 }