Esempio n. 1
0
        internal protected override DataNode OnSerialize(SerializationContext serCtx, object mapData, object obj)
        {
            string ctype = null;

            if (obj.GetType() != ValueType)
            {
                if (obj is IExtendedDataItem)
                {
                    // This is set by fallback types, to make sure the original type name is serialized back
                    ctype = (string)((IExtendedDataItem)obj).ExtendedProperties ["__raw_ctype"];
                }
                if (ctype == null)
                {
                    DataType subtype = Context.GetConfigurationDataType(obj.GetType());
                    DataNode n       = subtype.Serialize(serCtx, mapData, obj);
                    DataItem it      = n as DataItem;
                    if (it == null)
                    {
                        it     = new DataItem();
                        n.Name = "Value";
                        it.ItemData.Add(n);
                    }
                    it.ItemData.Add(new DataValue("ctype", subtype.Name));
                    it.Name = Name;
                    return(it);
                }
            }

            DataItem item = new DataItem();

            item.Name = Name;

            ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem(obj);

            if (citem != null)
            {
                ClassTypeHandler handler = new ClassTypeHandler(serCtx, this);
                item.ItemData = citem.Serialize(handler);
            }
            else
            {
                item.ItemData = Serialize(serCtx, obj);
            }

            if (ctype != null)
            {
                item.ItemData.Add(new DataValue("ctype", ctype));
            }

            return(item);
        }
Esempio n. 2
0
        protected internal override void OnDeserialize(SerializationContext serCtx, object mapData, DataNode data, object obj)
        {
            DataItem        item  = (DataItem)data;
            ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem(obj);

            if (citem != null)
            {
                ClassTypeHandler handler = new ClassTypeHandler(serCtx, this);
                citem.Deserialize(handler, item.ItemData);
            }
            else
            {
                DeserializeNoCustom(serCtx, obj, item.ItemData);
            }
        }