public object LoadConfigurationData(SerializationContext serCtx, Type type, DataNode data)
        {
            DataType dataType = GetConfigurationDataType(type);

            return(dataType.Deserialize(serCtx, null, data));
        }
示例#2
0
        internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data)
        {
            DataItem item = data as DataItem;

            if (item == null)
            {
                throw new InvalidOperationException("Invalid value found for type '" + Name + "' " + data);
            }

            DataValue ctype = item ["ctype"] as DataValue;

            if (ctype != null && ctype.Value != Name)
            {
                bool     isFallbackType;
                DataType stype = FindDerivedType(ctype.Value, mapData, out isFallbackType);

                if (isFallbackType)
                {
                    // Remove the ctype attribute, to make sure it is not checked again
                    // by the fallback type
                    item.ItemData.Remove(ctype);
                }

                if (stype != null)
                {
                    DataNode desData = data;
                    if (stype.IsSimpleType)
                    {
                        desData = item.ItemData ["Value"];
                        if (desData == null)
                        {
                            throw new InvalidOperationException("Value node not found");
                        }
                    }
                    object sobj = stype.Deserialize(serCtx, mapData, desData);

                    // Store the original data type, so it can be serialized back
                    if (isFallbackType && sobj is IExtendedDataItem)
                    {
                        ((IExtendedDataItem)sobj).ExtendedProperties ["__raw_ctype"] = ctype.Value;
                    }

                    return(sobj);
                }
                else
                {
                    throw new InvalidOperationException("Type not found: " + ctype.Value);
                }
            }

            ConstructorInfo ctor = ValueType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);

            if (ctor == null)
            {
                throw new InvalidOperationException("Default constructor not found for type '" + ValueType + "'");
            }

            object obj = ctor.Invoke(null);

            Deserialize(serCtx, null, item, obj);
            return(obj);
        }
示例#3
0
 internal object OnDeserialize(SerializationContext serCtx, DataNode data)
 {
     return(dataType.Deserialize(serCtx, mapData, data));
 }