コード例 #1
0
        internal protected override DataNode OnSerialize(SerializationContext serCtx, object mdata, object collection)
        {
            MapData  mapData = (mdata != null) ? (MapData)mdata : GetDefaultData();
            DataItem item    = new DataItem();

            item.Name        = Name;
            item.UniqueNames = false;
            object pos = handler.GetInitialPosition(collection);

            while (handler.MoveNextItem(collection, ref pos))
            {
                object val = handler.GetCurrentItem(collection, pos);
                if (val == null)
                {
                    continue;
                }
                DataNode data = mapData.ItemType.Serialize(serCtx, mapData.ItemMapData, val);
                data.Name = mapData.ItemName;
                item.ItemData.Add(data);
            }
            return(item);
        }
コード例 #2
0
        internal DataCollection Serialize(SerializationContext serCtx, object obj)
        {
            DataCollection itemCol = new DataCollection();

            foreach (ItemProperty prop in Properties)
            {
                if (prop.ReadOnly || !prop.CanSerialize(serCtx, obj))
                {
                    continue;
                }
                object val = prop.GetValue(obj);
                if (val == null)
                {
                    continue;
                }
                if (!serCtx.IsDefaultValueSerializationForced(prop) && val.Equals(prop.DefaultValue))
                {
                    continue;
                }

                DataCollection col = itemCol;
                if (prop.IsNested)
                {
                    col = GetNestedCollection(col, prop.NameList, 0);
                }

                if (prop.ExpandedCollection)
                {
                    ICollectionHandler handler = prop.ExpandedCollectionHandler;
                    object             pos     = handler.GetInitialPosition(val);
                    while (handler.MoveNextItem(val, ref pos))
                    {
                        object item = handler.GetCurrentItem(val, pos);
                        if (item == null)
                        {
                            continue;
                        }
                        DataNode data = prop.Serialize(serCtx, obj, item);
                        data.Name = prop.SingleName;
                        col.Add(data);
                    }
                }
                else
                {
                    DataNode data = prop.Serialize(serCtx, obj, val);
                    if (data == null)
                    {
                        continue;
                    }
                    col.Add(data);
                }
            }

            if (obj is IExtendedDataItem)
            {
                // Serialize raw data which could not be deserialized
                DataItem uknData = (DataItem)((IExtendedDataItem)obj).ExtendedProperties ["__raw_data"];
                if (uknData != null)
                {
                    itemCol.Merge(uknData.ItemData);
                }
            }

            return(itemCol);
        }