protected override void ImplSerialize(out IValueUnit retVal, InterfaceType instance, SerializationContextType context) { IHierarchicalMetadataProvider <IValueUnit, IValueItemBase> ctx = null; IValueUnit curCtxLvl = null; ctx = context as IHierarchicalMetadataProvider <IValueUnit, IValueItemBase>; curCtxLvl = ctx.Hierarchy.Peek() as IValueUnit; if (curCtxLvl != null && ctx != null && ctx.Metadata != null) { curCtxLvl.Add("SerializationManager", GetType().AssemblyQualifiedName); } retVal = ImplFactory.Serialize(instance, context); } // End of ImplSerialize (...)
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 (...)
} // 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 (...)