protected virtual Boolean ImplDeserializeItem(
     out Object retVal,
     Object item,
     IHierarchicalMetadataSerializationContext context)
 => ImplDeserializeItem(out retVal,
                        item,
                        delegate() { return(context.Hierarchy.Peek()); },
                        context);
Пример #2
0
 private Boolean _DeserializeEnumerable(
     PropertyDescriptor pd,
     IValueProvider <IEnumerable> sequence,
     IHierarchicalMetadataSerializationContext context)
 {
     return(sequence == null
                 ? false
                 : _DeserializeEnumerable(pd, sequence.Value, context));
 } // End of _DeserializeEnumerable (...)
Пример #3
0
        protected ValueObject(IValueUnit valueUnit,
                              IHierarchicalMetadataSerializationContext context)
            : this()
        {
            __context   = context;
            __valueUnit = valueUnit;

            ImplFillValues(valueUnit, context);
        } // End of Custom (Deserialization) Constructor
        } // End of ImplPopulateSequence (...)

        protected virtual void ImplSerializeEnumerable(
            out IValueSequence retVal,
            SequenceType instance,
            IHierarchicalMetadataSerializationContext context)
        {
            ArrayList sequenceValues;

            if (ImplSerializeEnumerable(out sequenceValues, instance, context))
            {
                retVal = new ValueSequence(sequenceValues);
            }
            else
            {
                retVal = null;
            }
        } // End of ImplSerializeEnumerable (...)
Пример #5
0
        } // End of ImplDeserializeEnumerable (...)

        protected virtual Object ImplDeserializeObject(
            IValueUnit objectVu,
            IHierarchicalMetadataSerializationContext context)
        {
            IValueUnit objCtxtLvl             = null;
            ISerializable <IValueUnit> serMgr = null;
            ValueDomObjectSerializationManagerCollection serMgrColl = null;
            ObjectSerializationManagerDescr serMgrDescr             = null;
            String     typeName  = null;
            IValueItem valueItem = null;

            if ((objCtxtLvl = context.Hierarchy.Peek() as IValueUnit) == null)
            {
                return(null);
            }

            if ((valueItem = objCtxtLvl ["SerializationManager"] as IValueItem) == null)
            {
                return(null);
            }

            if (valueItem.Value == null)
            {
                return(null);
            }

            if ((typeName = valueItem.Value.ToString()) == null)
            {
                return(null);
            }

            if ((serMgrColl = ValueDomObjectSerializationManagerCollection.Singleton) == null)
            {
                return(null);
            }

            if ((serMgrDescr = serMgrColl [typeName]) == null)
            {
                return(null);
            }

            return((serMgr = serMgrDescr.SerializationManager) == null
                        ? null : serMgr.Deserialize(objectVu, context));
        } // End of ImplDeserializeObject (...)
        } // End of ImplSerializeEnumerable (...)

        protected virtual Boolean ImplSerializeItem(
            out Object serializedItem,
            Action contextPrologDlg,
            Action contextEpilogDlg,
            Object itemValue,
            IHierarchicalMetadataSerializationContext context)
        {
            IValueUnit ctxUnit = null;
            IValueUnit subUnit = null;

            if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null)
            {
                serializedItem = null;

                return(false);
            }

            if (ImplIsBuiltinType(itemValue.GetType()))
            {
                /* ctxts.Add ( null ); */ serializedItem = itemValue;
            }
            else if (ImplIsString(itemValue.GetType()))
            {
                /* ctxts.Add ( null ); */ serializedItem = itemValue;
            }
            //else if ( ImplSerializeEnumerable ( retVal, pd.Name, item as IEnumerable, context ) )
            //    continue;
            else if (ImplSerializeObject(
                         out subUnit,
                         contextPrologDlg,
                         contextEpilogDlg,
                         itemValue, //as IValueObjectContract,
                         context))
            {
                serializedItem = subUnit;
            }
            else
            {
                serializedItem = null;
            }

            return(true);
        } // End of ImplSerializeItem (...)
        } // End of ImplDeserializeEnumerable (...)

        protected virtual IEnumerable ImplDeserializeEnumerable(
            IEnumerable value,
            IHierarchicalMetadataSerializationContext context)
        {
            IValueProvider <IEnumerable> valueSequence = context.Hierarchy.Peek()
                                                         as IValueSequence;

            if (valueSequence == null)
            {
                yield break;
            }
            if (valueSequence.Value == null)
            {
                yield break;
            }

            IEnumerator ctxtEnumerator = valueSequence.Value.GetEnumerator();

            foreach (Object item in value)
            {
                if (!ctxtEnumerator.MoveNext())
                {
                    yield break;
                }
                else
                {
                    context.Hierarchy.Push(ctxtEnumerator.Current as IValueItemBase);

                    try
                    {
                        if (ImplDeserializeItem(out Object retVal, item, context))
                        {
                            yield return(retVal);
                        }
                        else
                        {
                            yield break;
                        }
                    } finally { context.Hierarchy.Pop(); }
                }
            }
        } // End of ImplDeserializeEnumerable (...)
        } // End  of ImplDeserializeItem (...)

        protected virtual Type ImplGetItemType(IHierarchicalMetadataSerializationContext context)
        {
            if (context == null)
            {
                return(null);
            }

            IValueItem itemCtxtVi = null;
            IValueUnit itemCtxtVu = context.Hierarchy.Peek() as IValueUnit;

            if (itemCtxtVu == null)
            {
                return(null);
            }
            if ((itemCtxtVi = itemCtxtVu ["TypeGuid"]) == null)
            {
                return(null);
            }

            GuidTypeMapping.Item tmp = GuidTypeMapping.Singleton [
                new Guid(itemCtxtVi.Value as String)];

            return(tmp == null ? null : tmp.Type);
        } // End of ImplGetItemType (...)
Пример #9
0
        } // End of _DeserializeEnumerable (...)

        private Boolean _DispatchDeserializeEnumerable(
            PropertyDescriptor pd,
            dynamic sequence,
            IHierarchicalMetadataSerializationContext context)
        => _DeserializeEnumerable(pd, sequence, context);
Пример #10
0
        } // End of _DeserializeEnumerable (...)

        private Boolean _DeserializeEnumerable(
            PropertyDescriptor pd,
            IEnumerable sequence,
            IHierarchicalMetadataSerializationContext context)
        {
            if (pd == null)
            {
                return(false);
            }
            if (!typeof(IEnumerable).IsAssignableFrom(pd.PropertyType))
            {
                return(false);
            }
            if (sequence == null)
            {
                return(false);
            }

            IValueUnit curCtxLvl = context.Hierarchy.Peek() as IValueUnit;
            Object     propValue = pd.GetValue(this);

            if (curCtxLvl == null)
            {
                return(false);
            }

            IValueItem     valueItem = curCtxLvl [pd.Name] as IValueItem;
            IValueSequence subCtxt   = null;

            if (valueItem == null)
            {
                return(false);
            }
            if ((subCtxt = valueItem.Value as IValueSequence) == null)
            {
                return(false);
            }

            context.Hierarchy.Push(subCtxt);

            try
            {
                IEnumerator enumerator = ImplDeserializeEnumerable(
                    sequence, context).GetEnumerator();
                IList retColl = null;

                if (enumerator == null)
                {
                    return(false);
                }
                if (!enumerator.MoveNext())
                {
                    return(false);
                }

                if ((retColl = propValue as IList) == null)
                {
                    Type collType = pd.PropertyType;

                    if (collType.IsInterface)
                    {
                        if (collType.IsGenericType)
                        {
                            if (collType.Name == "IList`1")
                            {
                                collType = typeof(System.Collections.Generic.List <>).MakeGenericType(collType.GenericTypeArguments);
                            }
                        }
                    }

                    System.Reflection.ConstructorInfo ci = collType.GetConstructor(Type.EmptyTypes);

                    if (ci == null)
                    {
                        return(false);
                    }
                    if ((retColl = ci.Invoke(Type.EmptyTypes) as IList) == null)
                    {
                        return(false);
                    }

                    pd.SetValue(this, retColl);   //retVal = retColl;
                }

                do
                {
                    retColl.Add(enumerator.Current);
                }while (enumerator.MoveNext());
            }
            finally { context.Hierarchy.Pop(); }

            return(true);
        } // End of _DeserializeEnumerable (...)
Пример #11
0
 private Boolean _DeserializeEnumerable(
     PropertyDescriptor pd,
     String sequence,
     IHierarchicalMetadataSerializationContext context)
 => false;
        protected override Boolean ImplSerializeEnumerable(
            out ArrayList values,
            IEnumerable objValue,
            IHierarchicalMetadataSerializationContext context)
        {
            values = new ArrayList();

            if (objValue == null)
            {
                return(false);
            }
            if (context == null)
            {
                return(false);
            }

            IValueSequence valueSeq = context.Hierarchy.Peek() as IValueSequence;

            if (valueSeq == null)
            {
                return(false);
            }

            IList ctxts = valueSeq.Value as IList;

            if (ctxts == null)
            {
                return(false);
            }

            IValueUnit ctxUnit  = null;
            Type       instType = null;

            context.Hierarchy.Pop();

            if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null)
            {
                return(false);
            }

            // Add SerMgr key
            if ((instType = typeof(SequenceType)).IsGenericType)
            {
                ctxUnit.Add("SerializationManager",
                            GetType().GetGenericTypeDefinition().AssemblyQualifiedName);

                ArrayList typeParamGuids = new ArrayList();

                foreach (Type par in instType.GenericTypeArguments)
                {
                    typeParamGuids.Add(par.GetTypeGuid().ToString());
                }

                ctxUnit.Add("SerializationManagerInstanceTypeParamGuids",
                            new ValueSequence(typeParamGuids));
            }
            else
            {
                return(false);// ctxUnit.Add ( "SerializationManager", instType.AssemblyQualifiedName );
            }
            context.Hierarchy.Push(valueSeq);

            foreach (KeyValuePair <SequenceKeyType, SequenceValueType> kvp in objValue)
            {
                ValueUnit kvpValueUnit = new ValueUnit();
                Object    tmpValue     = null;

                ctxts.Add(ctxUnit = new ValueUnit());

                context.Hierarchy.Push(ctxUnit);

                ImplSerializeItem(
                    out tmpValue,
                    //delegate ( IValueUnit vu ) { ctxUnit.Add ( nameof ( kvp.Key ), vu ); },
                    delegate() {
                    ValueUnit vu = new ValueUnit();

                    ctxUnit.Add(nameof(kvp.Key), vu);
                    context.Hierarchy.Push(vu);
                },
                    delegate() { context.Hierarchy.Pop(); },
                    kvp.Key,
                    context);

                kvpValueUnit.Add(new ValueItem(nameof(kvp.Key), tmpValue));

                ImplSerializeItem(
                    out tmpValue,
                    //delegate ( IValueUnit vu ) { ctxUnit.Add ( nameof ( kvp.Value ), vu ); },
                    delegate() {
                    ValueUnit vu = new ValueUnit();

                    ctxUnit.Add(nameof(kvp.Value), vu);
                    context.Hierarchy.Push(vu);
                },
                    delegate() { context.Hierarchy.Pop(); },
                    kvp.Value,
                    context);

                kvpValueUnit.Add(new ValueItem(nameof(kvp.Value), tmpValue));

                values.Add(kvpValueUnit);

                context.Hierarchy.Pop();
            }

            return(true);
        } // End of ImplSerializeEnumerable (...)
Пример #13
0
        } // End of ImplDeserializeObject (...)

        protected virtual void ImplFillValues(
            IValueUnit valueUnit,
            IHierarchicalMetadataSerializationContext context)
        {
            IValueUnit curCtxLvl = null;

            if (context == null)
            {
                return;
            }
            if (context.Hierarchy == null)
            {
                return;
            }
            if ((curCtxLvl = context.Hierarchy.Peek() as IValueUnit) == null)
            {
                return;
            }

            //NumericStringValue              numericString   = null;
            PropertyDescriptorCollection pdc = null;
            String         propStrValue      = String.Empty;
            Type           propType          = null;
            Object         propValue         = null;
            IValueUnit     subUnit           = null;
            IValueItem     valueItem         = null;
            IValueItemBase valueItemBase     = null;

            //pdc = TypeDescriptor.GetProperties ( ImplGetSerializationContract ( context ) );
            pdc = ImplGetSerializationContract(context).GetAllInterfaceProperties();

            foreach (PropertyDescriptor pd in pdc)
            {
                if ((valueItemBase = valueUnit [pd.Name]) == null)
                {
                    continue;
                }
                if ((valueItem = valueItemBase as IValueItem) == null)
                {
                    continue;
                }

                if (valueItem.ValueBinder == null)
                {
                    if (typeof(IPrimitiveTypeValue).IsAssignableFrom(pd.PropertyType))
                    {
                        valueItem.ValueBinder = new ValueItemPrimitiveTypeValuePdBinder(pd, this);
                    }
                    else
                    {
                        valueItem.ValueBinder = new ValueItemObjectValuePdBinder(pd, this);
                    }
                }

                if ((subUnit = valueItem.Value as IValueUnit) == null)
                {
                    //if ( (numericString = valueItem.Value as NumericStringValue) != null )
                    //    propValue = numericString.ToType ( pd.PropertyType, null );
                    //else if ( valueItem.Value is String ) // String is enumerable...
                    //    propValue = valueItem.Value;
                    //else if ( _DispatchDeserializeEnumerable ( pd, valueItem.Value, context ) )
                    //    continue;
                    //else
                    //    propValue = valueItem.Value;
                    if (_DispatchDeserializeEnumerable(pd, valueItem.Value, context))
                    {
                        continue;
                    }
                    else if (valueItem.AlignBoundValueToValue())
                    {
                        continue;
                    }
                }
                else
                {
                    if ((valueItem = curCtxLvl [pd.Name] as IValueItem) == null)
                    {
                        propValue = null;
                    }
                    else
                    {
                        context.Hierarchy.Push(valueItem.Value as IValueUnit);

                        try { propValue = ImplDeserializeObject(subUnit, context); }
                        finally { context.Hierarchy.Pop(); }
                    }
                }

                propType = pd.PropertyType;

                //propValue = propStrValue; // Default serializer...

                if (Type.GetTypeCode(propType) == TypeCode.DateTime &&
                    (propStrValue = propValue as String) != null)
                {
                    pd.SetValue(this, DateTime.ParseExact(propStrValue, "o", null));
                }
                else if (ImplIsBuiltinType(propType))
                {
                    pd.SetValue(this, propValue);
                }
                else if (ImplIsString(propType))
                {
                    Type primValType = propType.GetInterface("IHasPrimitiveValue`1");

                    if (primValType == null)
                    {
                        pd.SetValue(this, propValue);
                    }
                    else
                    {
                        PropertyDescriptor pvPd = TypeDescriptor.GetProperties(propType
                                                                               ).Find("PrimitiveValue", true);
                        Object pvObj = null;

                        if ((pvObj = pd.GetValue(this)) == null)
                        {
                            pd.SetValue(this, pvObj = Activator.CreateInstance(propType));
                        }

                        pvPd.SetValue(pvObj, propValue);
                    }
                }
                else //if ( (subUnit = valueItemBase as IValueUnit) != null )
                {
                    pd.SetValue(this, propValue);
                }
            }
        } // End of ImplFillValues (...)
        } // End of ImplSerializeEnumerable (...)

        protected virtual Boolean ImplSerializeEnumerable(
            out ArrayList values,
            IEnumerable objValue,
            IHierarchicalMetadataSerializationContext context)
        {
            values = new ArrayList();

            if (objValue == null)
            {
                return(false);
            }
            if (context == null)
            {
                return(false);
            }

            IValueSequence valueSeq = context.Hierarchy.Peek() as IValueSequence;

            if (valueSeq == null)
            {
                return(false);
            }

            IList ctxts = ((IValueItemBase)valueSeq).Value as IList;

            if (ctxts == null)
            {
                return(false);
            }

            IValueUnit ctxUnit    = null;
            Type       itemType   = null;
            Type       serMgrType = null;
            IValueUnit subUnit    = null;

            context.Hierarchy.Pop();

            try
            {
                if ((ctxUnit = context.Hierarchy.Peek() as IValueUnit) == null)
                {
                    return(false);
                }
                else if ((serMgrType = GetType()).IsGenericType)
                {
                    ctxUnit.Add("SerializationManager",
                                serMgrType.GetGenericTypeDefinition().AssemblyQualifiedName);

                    ArrayList typeParamGuids = new ArrayList();

                    foreach (Type par in serMgrType.GenericTypeArguments)
                    {
                        typeParamGuids.Add(par.GetTypeGuid().ToString());
                    }

                    ctxUnit.Add("SerializationManagerInstanceTypeParamGuids",
                                new ValueSequence(typeParamGuids));
                }
                else
                {
                    ctxUnit.Add("SerializationManager", serMgrType.AssemblyQualifiedName);
                }
            }
            finally { context.Hierarchy.Push(valueSeq); }

            foreach (Object item in objValue)
            {
                if (ImplIsBuiltinType(itemType = item.GetType()))
                {
                    ValueUnit vu = new ValueUnit();

                    vu.Add(new ValueItem("TypeGuid", itemType.GetTypeGuid().ToString()));
                    ctxts.Add(vu);
                    values.Add(item);
                }
                else if (ImplIsString(item.GetType()))
                {
                    ctxts.Add(null); values.Add(item);
                }
                //else if ( ImplSerializeEnumerable ( retVal, pd.Name, item as IEnumerable, context ) )
                //    continue;
                else if (ImplSerializeObject(
                             out subUnit,
                             //delegate ( IValueUnit vu ) { ctxts.Add ( vu ); },
                             delegate() {
                    ValueUnit vu = new ValueUnit();

                    ctxts.Add(vu);
                    context.Hierarchy.Push(vu);
                },
                             delegate() { context.Hierarchy.Pop(); },
                             item, //as IValueObjectContract,
                             context))
                {
                    values.Add(subUnit);
                }
            }

            return(true);
        } // End of ImplSerializeEnumerable (...)
Пример #15
0
 private void _Reset()
 {
     __context   = null;
     __valueUnit = null;
 } // End of _Reset ()
Пример #16
0
 public BaseObject ( IValueUnit                                  valueUnit,
                     IHierarchicalMetadataSerializationContext   context )
     : base ( valueUnit, context ) { }
Пример #17
0
 protected CompositedIdObject(IValueUnit valueUnit,
                              IHierarchicalMetadataSerializationContext context)
     : base(valueUnit, context)
 {
     _Reset();
 }
        //protected override Boolean ImplAddSequenceItem ( SequenceType sequence, Object item )
        //{
        //    if ( !(item is SequenceItemType) ) return false;

        //    SequenceItemType kvp = (SequenceItemType) item;

        //    try { sequence.Add ( kvp.Key, kvp.Value ); }
        //    catch { return false; }

        //    return true;
        //} // End of ImplAddSequenceItem (...)

        protected override Boolean ImplDeserializeItem(
            out Object retVal,
            Object item,
            IHierarchicalMetadataSerializationContext context)
        {
            retVal = null;

            IValueItem curCtxtLvlVi = null;
            KeyValuePair <SequenceKeyType,
                          SequenceValueType> kvp;
            IValueUnit        kvpVu;
            IValueUnit        kvpCtxtLvl = null;
            SequenceKeyType   kvpKey     = default(SequenceKeyType);
            SequenceValueType kvpValue   = default(SequenceValueType);
            IValueItem        valueItem  = null;

            if (context == null)
            {
                return(false);
            }
            if ((kvpVu = item as IValueUnit) == null)
            {
                return(false);
            }
            if (kvpVu.Count != 2)
            {
                return(false);
            }
            if ((kvpCtxtLvl = context.Hierarchy.Peek() as IValueUnit) == null)
            {
                return(false);
            }

            // Deserialize the Key
            if ((valueItem = kvpVu [nameof(kvp.Key)]) == null)
            {
                return(false);
            }

            if ((curCtxtLvlVi = kvpCtxtLvl [nameof(kvp.Key)]) == null)
            {
                context.Hierarchy.Push(null);
            }
            else
            {
                context.Hierarchy.Push(curCtxtLvlVi.Value as IValueUnit);
            }

            try
            {
                if (!base.ImplDeserializeItem(out Object key, valueItem.Value, context))
                {
                    return(false);
                }

                kvpKey = (SequenceKeyType)key;
            } finally { context.Hierarchy.Pop(); }


            // Deserialize the Value
            if ((valueItem = kvpVu [nameof(kvp.Value)]) == null)
            {
                return(false);
            }

            if ((curCtxtLvlVi = kvpCtxtLvl [nameof(kvp.Value)]) == null)
            {
                context.Hierarchy.Push(null);
            }
            else
            {
                context.Hierarchy.Push(curCtxtLvlVi.Value as IValueUnit);
            }

            try
            {
                if (!base.ImplDeserializeItem(out Object value, valueItem.Value, context))
                {
                    return(false);
                }

                kvpValue = (SequenceValueType)value;
            } finally { context.Hierarchy.Pop(); }

            kvp    = new KeyValuePair <SequenceKeyType, SequenceValueType> (kvpKey, kvpValue);
            retVal = kvp;

            return(true);
        } // End of ImplDeserializeItem (...)
Пример #19
0
        protected virtual IEnumerable ImplDeserializeEnumerable(
            IEnumerable value,
            IHierarchicalMetadataSerializationContext context)
        {
            ISerializable <IValueUnit> serMgr = null;
            IValueUnit subCtxtLvl             = null;
            IValueUnit subUnit = null;
            IValueProvider <IEnumerable> valueSequence = null;

            valueSequence = context.Hierarchy.Peek() as IValueSequence;

            if (valueSequence == null)
            {
                yield break;
            }
            if (valueSequence.Value == null)
            {
                yield break;
            }

            IEnumerator ctxtEnumerator = valueSequence.Value.GetEnumerator();

            foreach (Object item in value)
            {
                if (!ctxtEnumerator.MoveNext())
                {
                    yield break;
                }
                else if ((subUnit = item as IValueUnit) == null)
                {
                    if (item is String)   // String is enumerable...
                    {
                        yield return(item);
                    }
                    else
                    {
                        //propValue = pd.GetValue ( InitDto );

                        //if ( _DeserializeEnumerable ( ref propValue, pd, valueItem.Value, context ) )
                        //    continue;
                        //else
                        //    propValue = valueItem.Value;
                    }
                }
                else
                {
                    if ((subCtxtLvl = ctxtEnumerator.Current as IValueUnit) == null)
                    {
                        yield return(null);
                    }
                    else
                    {
                        context.Hierarchy.Push(subCtxtLvl);

                        try     { yield return(serMgr.Deserialize(subUnit, context)); }
                        finally { context.Hierarchy.Pop(); }
                    }
                }
            }

            yield break;
        } // End of ImplDeserializeEnumerable (...)
Пример #20
0
        } // End of Custom Constructor

        protected Entity(IValueUnit valueUnit,
                         IHierarchicalMetadataSerializationContext context)
            : base(valueUnit, context)
        {
        }