Esempio n. 1
0
 /// <summary>
 /// Reconstitutes this object from the specified XmlSerializationContext.
 /// </summary>
 /// <param name="xmlsc">The specified XmlSerializationContext.</param>
 public void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_mass = (double)xmlsc.LoadObject("Mass");
     Temp   = (double)xmlsc.LoadObject("Temp");
     m_type = (MaterialType)xmlsc.LoadObject("Type");
     m_ssh.ReportChange();
 }
Esempio n. 2
0
        /// <summary>
        /// Reconstitutes this object from the specified XmlSerializationContext.
        /// </summary>
        /// <param name="xmlsc">The specified XmlSerializationContext.</param>
        public override void DeserializeFrom(XmlSerializationContext xmlsc)
        {
            m_model = (Model)xmlsc.ContextEntities["Model"];
            m_guid  = (Guid)xmlsc.LoadObject("Guid");

            base.DeserializeFrom(xmlsc);

            m_keepingTimingData = (bool)xmlsc.LoadObject("KeepingTimingData");

            #region >>> Do what else is in the constructor. <<<
            ExecutionDelegate = new EdgeExecutionDelegate(OnEdgeExecution);

            EdgeStartingEvent           += new EdgeEvent(OnEdgeStartingEvent);
            EdgeExecutionStartingEvent  += new EdgeEvent(OnEdgeExecutionStartingEvent);
            EdgeExecutionFinishingEvent += new EdgeEvent(OnEdgeExecutionFinishingEvent);
            EdgeFinishingEvent          += new EdgeEvent(OnEdgeFinishingEvent);

            StructureChangeHandler += new StructureChangeHandler(MyStructureChangedHandler);

            ValidityChangeEvent += new Graphs.Validity.ValidityChangeHandler(Task_ValidityChangeEvent);

            ResetDurationData();

            #endregion
        }
Esempio n. 3
0
        private void storeXML(TestGraph1 tg1)
        {
            XmlSerializationContext xmlsc = new XmlSerializationContext();

            xmlsc.StoreObject("TG", tg1);
            xmlsc.Save(System.Environment.GetEnvironmentVariable("TEMP") + "\\TestGraphPersistence.xml");
        }
Esempio n. 4
0
        public object ReadXml(XmlReader reader, XmlSerializationContext context)
        {
            var value = context.Contract.CreateDefault();

            ((IXmlSerializable)value).ReadXml(reader);
            return(value);
        }
Esempio n. 5
0
            /// <summary>
            /// Deserializes this object from the specified XmlSerializatonContext.
            /// </summary>
            /// <param name="xmlsc">The XmlSerializatonContext from which this object is to be reconstituted.</param>
            public void DeserializeFrom(XmlSerializationContext xmlsc)
            {
                model = (Model)xmlsc.ContextEntities["Model"];
                Task rootTask = (Task)xmlsc.LoadObject("Parent");

                tp = new TaskProcessor(model, "TP_Reloaded", Guid.NewGuid(), rootTask);
                tp.KeepGraphContexts = true;

                foreach (TestTask task in tp.MasterTask.GetChildTasks(false))
                {
                    if (task.Name.Equals("TaskA"))
                    {
                        ta = task;
                    }
                    if (task.Name.Equals("TaskB"))
                    {
                        tb = task;
                    }
                    if (task.Name.Equals("TaskC"))
                    {
                        tc = task;
                    }
                    if (task.Name.Equals("TaskD"))
                    {
                        td = task;
                    }
                }
            }
        public void WriteXml(XmlWriter writer, object value, XmlSerializationContext context)
        {
            if (value == null)
            {
                return;
            }

            if (context.Member.MappingType != XmlMappingType.Element)
            {
                throw new XmlSerializationException(string.Format("XML mapping of \"{0}\" must be Element.", context.ValueType));
            }

            var target   = value;
            var contract = context.Contract.ToObjectContract();

            foreach (var property in contract.Properties)
            {
                if (CanWriteProperty(property))
                {
                    var propertyValue = GetValue(value, property);

                    if (!property.IsCollection)
                    {
                        context.Serialize(writer, propertyValue, property);
                    }
                    else
                    {
                        context.SerializeBody(writer, propertyValue, property);
                    }
                }
            }
        }
Esempio n. 7
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     if (identificationMode == XmlIdentificationMode.Identifier)
     {
         var model = context.Root as Model;
         if (model != null)
         {
             var modelElement = obj as IModelElement;
             if (modelElement != null)
             {
                 Uri uri;
                 if (modelElement.Model == model)
                 {
                     uri = modelElement.RelativeUri;
                 }
                 else
                 {
                     uri = MakeShortUri(modelElement.AbsoluteUri, model.ModelUri);
                 }
                 if (uri != null)
                 {
                     writer.WriteString(uri.ConvertToString());
                     return true;
                 }
             }
         }
     }
     return base.WriteIdentifiedObject(writer, obj, identificationMode, info, context);
 }
 protected virtual void OnUnknownProperty(XmlReader reader, object target, XmlSerializationContext context)
 {
     if (reader.NodeType == XmlNodeType.Element)
     {
         reader.Skip();
     }
 }
Esempio n. 9
0
 protected override void InitializeElementProperties(XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     var model = obj as Model;
     if (model == null)
     {
         base.InitializeElementProperties(reader, ref obj, info, context);
     }
     else
     {
         int currentDepth = reader.Depth;
         while (reader.Depth < currentDepth || reader.Read())
         {
             if (reader.Depth == currentDepth)
             {
                 break;
             }
             else if (reader.Depth < currentDepth)
             {
                 return;
             }
             if (reader.NodeType == XmlNodeType.Element)
             {
                 var element = CreateRoot(reader) as IModelElement;
                 Initialize(reader, element, context);
                 if (element != null)
                 {
                     model.RootElements.Add(element);
                 }
             }
         }
     }
 }
Esempio n. 10
0
        private void loadXML(ref TestGraph1 tg1)
        {
            XmlSerializationContext xmlsc = new XmlSerializationContext();

            xmlsc.Load(System.Environment.GetEnvironmentVariable("TEMP") + "\\TestGraphPersistence.xml");
            xmlsc.ContextEntities.Add("Model", new Model("Reconstituted Model"));
            tg1 = (TestGraph1)xmlsc.LoadObject("TG");
        }
        public object ReadXml(XmlReader reader, XmlSerializationContext context)
        {
            if (context.Member.MappingType != XmlMappingType.Element)
            {
                throw new XmlSerializationException($"XML mapping of \"{context.ValueType}\" must be Element.");
            }

            var contract = context.Contract.ToObjectContract();
            var target   = CreateTarget(contract);

            var propertyInfos = XmlPropertyInfo.GetInfo(contract, reader.NameTable, context);

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    ReadProperty(reader, target, propertyInfos, XmlMappingType.Attribute, context);
                }while (reader.MoveToNextAttribute());

                reader.MoveToElement();
            }

            if (!reader.IsEmptyElement)
            {
                if (contract.InnerTextProperty != null)
                {
                    var value = context.Deserialize(reader, contract.InnerTextProperty);
                    SetValue(target, contract.InnerTextProperty, value);
                }
                else
                {
                    reader.ReadStartElement();

                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            ReadProperty(reader, target, propertyInfos, XmlMappingType.Element, context);
                        }
                        else
                        {
                            reader.Read();
                        }
                    }

                    reader.Read();
                }
            }
            else
            {
                reader.Read();
            }

            SetDefaultProperties(contract, target, propertyInfos);

            return(GetResult(target));
        }
Esempio n. 12
0
 protected override void SerializeMembers (XmlSerializationContext context)
 {
     var writer = context.Writer;
     writer.WriteStartElement ("u", response ? ActionName + "Response" : ActionName, ServiceType);
     foreach (var argument in arguments) {
         writer.WriteElementString (argument.Key, argument.Value);
     }
     writer.WriteEndElement ();
 }
Esempio n. 13
0
 /// <summary>
 /// Reconstitutes this object from the specified XmlSerializationContext.
 /// </summary>
 /// <param name="xmlsc">The specified XmlSerializationContext.</param>
 public override void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     base.DeserializeFrom(xmlsc);
     m_name                     = (string)xmlsc.LoadObject("Name");
     m_guid                     = (Guid)xmlsc.LoadObject("Guid");
     m_specificGravity          = (double)xmlsc.LoadObject("SpecificGravity");
     m_specificHeat             = (double)xmlsc.LoadObject("SpecificHeat");
     m_latentHeatOfVaporization = (double)xmlsc.LoadObject("LHOV");
 }
Esempio n. 14
0
 /// <summary>
 /// Stores this object to the specified XmlSerializationContext.
 /// </summary>
 /// <param name="xmlsc">The specified XmlSerializationContext.</param>
 public override void SerializeTo(XmlSerializationContext xmlsc)
 {
     base.SerializeTo(xmlsc);
     xmlsc.StoreObject("Name", m_name);
     xmlsc.StoreObject("Guid", m_guid);
     xmlsc.StoreObject("SpecificGravity", m_specificGravity);
     xmlsc.StoreObject("SpecificHeat", m_specificHeat);
     xmlsc.StoreObject("LHOV", m_latentHeatOfVaporization);
 }
Esempio n. 15
0
 /// <summary>
 /// Reconstitutes this object from the specified XmlSerializationContext.
 /// </summary>
 /// <param name="xmlsc">The specified XmlSerializationContext.</param>
 public void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_name      = (string)xmlsc.LoadObject("Name");
     m_guid      = (Guid)xmlsc.LoadObject("Guid");
     m_energy    = (double)xmlsc.LoadObject("Energy");
     m_products  = (ArrayList)xmlsc.LoadObject("Products");
     m_reactants = (ArrayList)xmlsc.LoadObject("Reactants");
     m_rxPct     = (double)xmlsc.LoadObject("ReactionPercentage");
 }
Esempio n. 16
0
 /// <summary>
 /// Stores this object to the specified XmlSerializationContext.
 /// </summary>
 /// <param name="xmlsc">The specified XmlSerializationContext.</param>
 public void SerializeTo(XmlSerializationContext xmlsc)
 {
     xmlsc.StoreObject("Name", m_name);
     xmlsc.StoreObject("Guid", m_guid);
     xmlsc.StoreObject("Energy", m_energy);
     xmlsc.StoreObject("Products", m_products);
     xmlsc.StoreObject("Reactants", m_reactants);
     xmlsc.StoreObject("ReactionPercentage", m_rxPct);
 }
        public override void WriteXml(XmlWriter writer, object value, XmlSerializationContext context)
        {
            var valueString = ToString((T)value, context);

            if (valueString != null)
            {
                writer.WriteRaw(valueString);
            }
        }
        public void WriteXml(XmlWriter writer, object value, XmlSerializationContext context)
        {
            var underlyingType = context.ValueType.GetUnderlyingOptionalType();
            var optional       = value as IAnyOptional;

            var underlyingValue = optional.HasValue ? optional.Value : underlyingType.GetDefault();

            context.SerializeBody(writer, underlyingValue, underlyingType);
        }
Esempio n. 19
0
        public object GetValue(object input, XmlSerializationContext context)
        {
            var modelElement = (ModelElement)input;

            if (Reference.UpperBound == 1)
            {
                return(modelElement.GetReferencedElement(Reference));
            }
            return(modelElement.GetReferencedElements(Reference));
        }
Esempio n. 20
0
 public virtual void SerializeTo(XmlSerializationContext xmlsc)
 {
     xmlsc.StoreObject("ExecEventType", m_eet);
     xmlsc.StoreObject("Guid", m_guid);
     xmlsc.StoreObject("KeepGCs", m_keepGraphContexts);
     xmlsc.StoreObject("MasterTask", m_masterTask);
     xmlsc.StoreObject("Name", m_name);
     xmlsc.StoreObject("StartCondSpec", m_startConditionsSpecified);
     xmlsc.StoreObject("When", m_when);
 }
Esempio n. 21
0
 public virtual void SerializeTo(XmlSerializationContext xmlsc)
 {
     xmlsc.StoreObject("EventType", m_eventType);
     xmlsc.StoreObject("VertexCount", m_vertices.Length);
     for (int i = 0; i < m_vertices.Length; i++)
     {
         xmlsc.StoreObject("Vertex_" + i, m_vertices[i]);
     }
     // Skipping m_vsKey & m_executive.
 }
Esempio n. 22
0
        public object GetValue(object input, XmlSerializationContext context)
        {
            var modelElement = (IModelElement)input;

            if (Attribute.UpperBound == 1)
            {
                return(modelElement.GetAttributeValue(Attribute));
            }
            return(modelElement.GetAttributeValues(Attribute));
        }
Esempio n. 23
0
 public object GetValue(object input, XmlSerializationContext context)
 {
     if (context is XmiSerializationContext)
     {
         return ((XmiSerializationContext)context).GetId(input);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 24
0
 public void SetValue(object input, object value, XmlSerializationContext context)
 {
     if (context is XmiSerializationContext)
     {
         ((XmiSerializationContext)context).SetId(input, value.ToString());
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 25
0
 /// <summary>
 /// Serializes this object to the specified XmlSerializatonContext.
 /// </summary>
 /// <param name="xmlsc">The XmlSerializatonContext into which this object is to be stored.</param>
 public void SerializeTo(XmlSerializationContext xmlsc)
 {
     xmlsc.StoreObject("NumberOfEntries", m_nEntries);
     //xmlsc.StoreObject("XVals",m_xVals);
     //xmlsc.StoreObject("YVals",m_yVals);
     for (int i = 0; i < m_nEntries; i++)
     {
         xmlsc.StoreObject("XVals_" + i, m_xVals[i]);
         xmlsc.StoreObject("YVals_" + i, m_yVals[i]);
     }
 }
Esempio n. 26
0
 /// <summary>
 /// Deserializes this object from the specified XmlSerializatonContext.
 /// </summary>
 /// <param name="xmlsc">The XmlSerializatonContext from which this object is to be reconstituted.</param>
 public void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_nEntries = (int)xmlsc.LoadObject("NumberOfEntries");
     m_xVals    = new double[m_nEntries];
     m_yVals    = new double[m_nEntries];
     for (int i = 0; i < m_nEntries; i++)
     {
         m_xVals[i] = (double)xmlsc.LoadObject("XVals_" + i);
         m_yVals[i] = (double)xmlsc.LoadObject("YVals_" + i);
     }
 }
Esempio n. 27
0
        protected override void SerializeMembers(XmlSerializationContext context)
        {
            var writer = context.Writer;

            writer.WriteStartElement("u", response ? ActionName + "Response" : ActionName, ServiceType);
            foreach (var argument in arguments)
            {
                writer.WriteElementString(argument.Key, argument.Value);
            }
            writer.WriteEndElement();
        }
Esempio n. 28
0
 public void SetValue(object input, object value, XmlSerializationContext context)
 {
     if (context is XmiSerializationContext)
     {
         ((XmiSerializationContext)context).SetId(input, value.ToString());
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 29
0
        public void Serialize(XmlSerializationContext <VirtualContext> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            context.AutoSerializeObjectStart(item);
            SerializeMembers(context);
            context.AutoSerializeObjectEnd(item);
        }
Esempio n. 30
0
 /// <summary>
 /// Deserializes this object from the specified XmlSerializatonContext.
 /// </summary>
 /// <param name="xmlsc">The XmlSerializatonContext from which this object is to be reconstituted.</param>
 public void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_model     = (Model)xmlsc.ContextEntities["Model"];
     m_name      = (string)xmlsc.LoadObject("Name");
     m_guid      = (Guid)xmlsc.LoadObject("Guid");
     m_resources = (ArrayList)xmlsc.LoadObject("Resources");
     foreach (IResource resource in m_resources)
     {
         resource.Manager = this;
     }
 }
Esempio n. 31
0
        public virtual void DeserializeFrom(XmlSerializationContext xmlsc)
        {
            m_masterTask = (Task)xmlsc.LoadObject("MasterTask");

            ArrayList tmpList = (ArrayList)xmlsc.LoadObject("ChildTasks");

            foreach (Task task in tmpList)
            {
                AppendTask(task);
            }
        }
Esempio n. 32
0
 public object GetValue(object input, XmlSerializationContext context)
 {
     if (context is XmiSerializationContext)
     {
         return ((XmiSerializationContext)context).GetId(input);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 33
0
 public virtual void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_model                    = (Model)xmlsc.ContextEntities["Model"];
     m_eet                      = (ExecEventType)xmlsc.LoadObject("ExecEventType");
     m_guid                     = (Guid)xmlsc.LoadObject("Guid");
     m_keepGraphContexts        = (bool)xmlsc.LoadObject("KeepGCs");
     m_masterTask               = (Task)xmlsc.LoadObject("MasterTask");
     m_name                     = (string)xmlsc.LoadObject("Name");
     m_startConditionsSpecified = (bool)xmlsc.LoadObject("StartCondSpec");
     m_when                     = (DateTime)xmlsc.LoadObject("When");
 }
Esempio n. 34
0
 /// <summary>
 /// Serializes this object to the specified XmlSerializatonContext.
 /// </summary>
 /// <param name="xmlsc">The XmlSerializatonContext into which this object is to be stored.</param>
 public void SerializeTo(XmlSerializationContext xmlsc)
 {
     if (xmlsc != null)
     {
         xmlsc.StoreObject("MaterialCatalog", m_materialCatalog);
         xmlsc.StoreObject("ReactionProcessor", m_reactionProcessor);
     }
     else
     {
         throw new ApplicationException("SerializeTo(...) called with a null XmlSerializationContext.");
     }
 }
Esempio n. 35
0
        public virtual void DeserializeFrom(XmlSerializationContext xmlsc)
        {
            // TODO:  Add Vertex.DeserializeFrom implementation
            m_exec      = ((Model)xmlsc.ContextEntities["Model"]).Executive;
            m_eventType = (ExecEventType)xmlsc.LoadObject("EventType");
            int vertexCount = (int)xmlsc.LoadObject("VertexCount");

            m_vertices = new Vertex[vertexCount];
            //for ( int i = 0 ; i < vertexCount ; i++ ) {
            throw new NotImplementedException("Vertex deserialization not yet implemented in VertexSynchronizers.");
            //}
        }
Esempio n. 36
0
 protected override void WriteElementProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     var model = obj as Model;
     if (model == null)
     {
         base.WriteElementProperties(writer, obj, info, context);
     }
     else
     {
         foreach (var element in model.RootElements)
         {
             Serialize(element, writer, null, true, XmlIdentificationMode.FullObject, context);
         }
     }
 }
Esempio n. 37
0
 public override void Serialize(object obj, XmlWriter writer, IPropertySerializationInfo property, bool writeInstance, XmlIdentificationMode identificationMode, XmlSerializationContext context)
 {
     var modelElement = obj as IModelElement;
     if (modelElement == null)
     {
         base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
     }
     else
     {
         var model = modelElement.Model;
         var modelContext = context as ModelSerializationContext;
         if (modelContext == null || model == modelContext.Model)
         {
             base.Serialize(obj, writer, property, writeInstance, identificationMode, context);
         }
         else
         {
             writer.WriteStartAttribute("href");
             WriteIdentifiedObject(writer, obj, property.IdentificationMode, GetSerializationInfo(obj.GetType(), false), context);
             writer.WriteEndAttribute();
         }
     }
 }
Esempio n. 38
0
 void IXmlSerializable.SerializeMembers (XmlSerializationContext context)
 {
     SerializeMembers (context);
 }
Esempio n. 39
0
 public void AddToCollection(object input, object item, XmlSerializationContext context)
 {
     if (!context.IsOppositeSet(input, this))
     {
         try
         {
             var collection = GetValue(input, context);
             PropertyType.AddToCollection(collection, item);
             context.BlockOpposite(item, this);
         }
         catch (InvalidCastException e)
         {
             throw new Exception($"The element {item} cannot be added to the property {ElementName} of {input} because the types do not match.", e);
         }
     }
 }
Esempio n. 40
0
 protected override void Serialize (XmlSerializationContext context)
 {
     throw new System.NotImplementedException ();
 }
Esempio n. 41
0
 protected override void SerializeMembers (XmlSerializationContext context)
 {
     AutoSerializeMembers (this, context);
 }
Esempio n. 42
0
 public void AddToCollection(object input, object item, XmlSerializationContext context)
 {
     throw new InvalidOperationException();
 }
Esempio n. 43
0
 private void ReadElementFromProperty(XmlReader reader, object obj, XmlSerializationContext context, IPropertySerializationInfo p)
 {
     var href = reader.GetAttribute("href");
     if (href == null)
     {
         if (p.PropertyType.IsStringConvertible || (p.PropertyType.IsCollection && p.PropertyType.CollectionItemType.IsStringConvertible))
         {
             string content = reader.ReadElementContentAsString();
             if (p.PropertyType.IsCollection)
             {
                 p.AddToCollection(obj, p.PropertyType.CollectionItemType.ConvertFromString(content), context);
             }
             else
             {
                 p.SetValue(obj, p.ConvertFromString(content), context);
             }
         }
         else
         {
             object current = DeserializeInternal(reader, p, context);
             if (p.PropertyType.IsCollection)
             {
                 p.AddToCollection(obj, current, context);
             }
             else
             {
                 p.SetValue(obj, current, context);
             }
         }
     }
     else
     {
         if (p.PropertyType.IsCollection)
         {
             EnqueueAddToPropertyDelay(p, obj, href, context);
         }
         else
         {
             EnqueueSetPropertyDelay(p, obj, href, context);
         }
     }
 }
Esempio n. 44
0
 public override void OnResolveIdentifiedObject(object instance, XmlSerializationContext context)
 {
     Type.AddToCollection(Target, instance);
 }
Esempio n. 45
0
 protected override bool OverrideIdentifiedObject(object obj, XmlReader reader, XmlSerializationContext context)
 {
     return false;
 }
Esempio n. 46
0
 public override void OnResolveIdentifiedObject(object instance, XmlSerializationContext context)
 {
     Property.SetValue(Target, instance, context);
 }
Esempio n. 47
0
 public abstract void OnResolveIdentifiedObject(object instance, XmlSerializationContext context);
Esempio n. 48
0
 protected override void HandleUnknownAttribute(XmlReader reader, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     if (reader.NamespaceURI == XmiArtificialIdAttribute.Instance.Namespace && reader.LocalName == XmiArtificialIdAttribute.Instance.ElementName)
     {
         XmiArtificialIdAttribute.Instance.SetValue(obj, reader.Value, context);
     }
     else
     {
         base.HandleUnknownAttribute(reader, obj, info, context);
     }
 }
Esempio n. 49
0
 protected override void SerializeMembersOnly(XmlSerializationContext context)
 {
     context.AutoSerializeMembersOnly (this);
 }
 public abstract object GetValue(object obj, XmlSerializationContext context);
Esempio n. 51
0
 protected override void SerializeSelfAndMembers(XmlSerializationContext context)
 {
     context.AutoSerializeObjectAndMembers (this);
 }
Esempio n. 52
0
 protected override void WriteElementProperties(System.Xml.XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     foreach (XmlPropertySerializationInfo pi in info.ElementProperties)
     {
         var value = pi.GetValue(obj, context);
         if (pi.ShouldSerializeValue(obj, value))
         {
             if (pi.PropertyType.IsCollection)
             {
                 var collectionType = pi.PropertyType.CollectionItemType.Type;
                 foreach (object item in value as IEnumerable)
                 {
                     writer.WriteStartElement(pi.NamespacePrefix, pi.ElementName, pi.Namespace);
                     var itemType = item.GetType();
                     var itemInfo = GetSerializationInfo(itemType, true);
                     if (itemType != collectionType)
                     {
                         WriteTypeQualifier(writer, itemInfo);
                     }
                     if (itemInfo.IsStringConvertible)
                     {
                         writer.WriteString(itemInfo.ConvertToString(item));
                     }
                     else
                     {
                         Serialize(item, writer, pi, false, pi.IdentificationMode, context);
                     }
                     writer.WriteEndElement();
                 }
             }
             else
             {
                 writer.WriteStartElement(pi.NamespacePrefix, pi.ElementName, pi.Namespace);
                 if (value != null)
                 {
                     var type = value.GetType();
                     if (type != pi.PropertyType.Type.GetImplementationType())
                     {
                         WriteTypeQualifier(writer, GetSerializationInfo(type, true));
                     }
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
                 Serialize(value, writer, pi, false, pi.IdentificationMode, context);
                 writer.WriteEndElement();
             }
         }
     }
 }
Esempio n. 53
0
 protected override void WriteElementProperties(XmlWriter writer, object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     var model = obj as Model;
     if (model == null)
     {
         base.WriteElementProperties(writer, obj, info, context);
     }
     else
     {
         foreach (var element in model.RootElements)
         {
             if (element == null) continue;
             var typeInfo = GetSerializationInfo(element.GetType(), true);
             writer.WriteStartElement(typeInfo.NamespacePrefix ?? RootPrefix, typeInfo.ElementName, typeInfo.Namespace);
             Serialize(element, writer, null, false, XmlIdentificationMode.FullObject, context);
             writer.WriteEndElement();
         }
     }
 }
 public void AddToCollection(object input, object item, XmlSerializationContext context)
 {
     if (!context.IsOppositeSet(input, this))
     {
         var collection = GetValue(input, context);
         PropertyType.AddToCollection(collection, item);
         context.BlockOpposite(item, this);
     }
 }
 public abstract void SetValue(object obj, object value, XmlSerializationContext context);
Esempio n. 56
0
 protected override void InitializeElementProperties(System.Xml.XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     int currentDepth = reader.Depth;
     while (reader.Depth < currentDepth || reader.Read())
     {
         if (reader.Depth == currentDepth)
         {
             break;
         }
         else if (reader.Depth < currentDepth)
         {
             return;
         }
         if (reader.NodeType == XmlNodeType.Element)
         {
             var found = false;
             foreach (IPropertySerializationInfo p in info.ElementProperties)
             {
                 if (IsPropertyElement(reader, p))
                 {
                     ReadElementFromProperty(reader, obj, context, p);
                     found = true;
                     break;
                 }
             }
             if (!found)
             {
                 foreach (IPropertySerializationInfo p in info.AttributeProperties)
                 {
                     if (IsPropertyElement(reader, p))
                     {
                         ReadElementFromProperty(reader, obj, context, p);
                         found = true;
                         break;
                     }
                 }
                 if (!found)
                 {
                     OnUnknownElement(new UnknownElementEventArgs(obj, reader.ReadOuterXml()));
                 }
             }
         }
     }
 }
Esempio n. 57
0
 void IXmlSerializable.Serialize (XmlSerializationContext context)
 {
     Serialize (context);
 }
Esempio n. 58
0
 protected override bool WriteIdentifiedObject(XmlWriter writer, object obj, XmlIdentificationMode identificationMode, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     return false;
 }
Esempio n. 59
0
 protected abstract void SerializeMembers (XmlSerializationContext context);
Esempio n. 60
0
 protected override string GetAttributeValue(object value, ITypeSerializationInfo info, XmlSerializationContext context)
 {
     var model = context.Root as Model;
     var modelElement = value as ModelElement;
     if (modelElement != null && model != null)
     {
         Uri uri;
         if (modelElement.Model == model)
         {
             uri = modelElement.RelativeUri;
         }
         else
         {
             uri = MakeShortUri(modelElement.AbsoluteUri, model.ModelUri);
         }
         if (uri != null)
         {
             return uri.ConvertToString();
         }
     }
     return base.GetAttributeValue(value, info, context);
 }