public object GetValue(object parentobject)
 {
     if (m_CurrentNode.HasAttribute("Type"))
     {
         string type = m_CurrentNode.GetAttribute("Type");
         // Get the surrogate for this type
         IXmlSerializationSurrogate surr = m_SurrogateSelector.GetSurrogate(type);
         if (null == surr)
         {
             throw new ApplicationException(string.Format("Unable to find XmlSurrogate for type {0}!", type));
         }
         else
         {
             PushNodeStack();
             m_CurrentNode = (XmlElement)m_CurrentNode.FirstChild;
             object retvalue = surr.Deserialize(null, this, parentobject);
             PopNodeStack();
             m_CurrentNode = (XmlElement)m_CurrentNode.NextSibling;
             return(retvalue);
         }
     }
     else
     {
         throw new ApplicationException(string.Format("Unable to deserialize element {0}, Type attribute missing!", m_CurrentNode.Name));
     }
 }
Beispiel #2
0
        /// <summary>Deserializes the embedded base type.</summary>
        /// <param name="instance">The instance of the object to deserialize.</param>
        /// <param name="fullyQualifiedBaseTypeName">Fully qualified base type name. It is the short name of the assembly, comma, the full type name, comma, and the version. The string must not contain whitespaces. Example: 'AltaxoBase,Altaxo.Main.DocumentPath,0'.</param>
        /// <param name="parent">The parent object of the current object to deserialize.</param>
        public object GetBaseValueEmbedded(object instance, string fullyQualifiedBaseTypeName, object parent)
        {
            object obj;

            if ("BaseType" == CurrentElementName)
            {
                string basetypestring         = _xmlReader.ReadElementString();
                IXmlSerializationSurrogate ss = _surrogateSelector.GetSurrogate(basetypestring);
                if (null == ss)
                {
                    throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", fullyQualifiedBaseTypeName));
                }
                obj = ss.Deserialize(instance, this, parent);
            }
            else
            {
                IXmlSerializationSurrogate ss = _surrogateSelector.GetSurrogate(fullyQualifiedBaseTypeName);
                if (null == ss)
                {
                    throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", fullyQualifiedBaseTypeName));
                }
                obj = ss.Deserialize(instance, this, parent);
            }
            return(obj);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a surrogate for the type <code>type</code>.
        /// </summary>
        /// <param name="type">The type for which the surrogate is added.</param>
        /// <param name="version">The version of the surrogate (higher version numbers mean more recent versions).</param>
        /// <param name="surrogate">The surrogate used to serialize/deserialize the type.</param>
        public void AddSurrogate(System.Type type, int version, IXmlSerializationSurrogate surrogate)
        {
            // if this attribute cares about a currently existing type,
            // consider the highest value of version among all attributes
            // which care for the same type as the current version of that type
            AddTypeAndVersionIfHigher(type, version, surrogate);

            _surrogates[GetFullyQualifiedTypeName(type, version)] = surrogate;
        }
Beispiel #4
0
        protected void AddTypeAndVersionIfHigher(System.Type type, int version, IXmlSerializationSurrogate surrogate)
        {
            int storedversion = _versions.ContainsKey(type) ? (int)(_versions[type] ?? 0) : int.MinValue;

            if (version > storedversion)
            {
                _versions[type]   = version;
                _surrogates[type] = surrogate;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Adds a surrogate for the type specified in the XmlSerializationForAttribute.
 /// </summary>
 /// <param name="attr">The attribute used to describe the type this surrogate is intended for.</param>
 /// <param name="surrogate">The surrogate used to serialize/deserialize the type.</param>
 public void AddSurrogate(XmlSerializationSurrogateForAttribute attr, IXmlSerializationSurrogate surrogate)
 {
     if (null != attr.SerializationType)
     {
         AddSurrogate(attr.SerializationType, attr.Version, surrogate);
     }
     else
     {
         AddSurrogate(attr.AssemblyName, attr.TypeName, attr.Version, surrogate);
     }
 }
        public void AddBaseValueEmbedded(object o, System.Type basetype)
        {
            IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetype);

            if (null == ss)
            {
                throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
            }
            else
            {
                ss.Serialize(o, this);
            }
        }
        public void AddBaseValueEmbedded(object o, System.Type basetype)
        {
            IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetype);

            if (null == ss)
            {
                throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
            }
            else
            {
                m_Writer.WriteElementString("BaseType", m_SurrogateSelector.GetFullyQualifiedTypeName(basetype));
                ss.Serialize(o, this);
            }
        }
        public void GetBaseValueStandalone(string name, object instance, System.Type basetype, object parent)
        {
            IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetype);

            if (null == ss)
            {
                throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
            }
            else
            {
                m_Reader.ReadStartElement(); // note: this must now be done by  in the deserialization code
                ss.Deserialize(instance, this, parent);
                m_Reader.ReadEndElement();
            }
        }
        public object GetValue(object parentobject)
        {
            string type = m_Reader.GetAttribute("Type");

            if (null != type)
            {
                if ("UndefinedValue" == type)
                {
                    m_Reader.Read();
                    return(null);
                }

                // Get the surrogate for this type
                IXmlSerializationSurrogate surr = m_SurrogateSelector.GetSurrogate(type);
                if (null == surr)
                {
                    throw new ApplicationException(string.Format("Unable to find XmlSurrogate for type {0}!", type));
                }
                else
                {
                    bool bNotEmpty = !m_Reader.IsEmptyElement;
                    // System.Diagnostics.Trace.WriteLine(string.Format("Xml val {0}, type {1}, empty:{2}",m_Reader.Name,type,bNotEmpty));


                    if (bNotEmpty)
                    {
                        m_Reader.ReadStartElement(); // note: this must now be done by  in the deserialization code
                    }
                    object retvalue = surr.Deserialize(null, this, parentobject);

                    if (bNotEmpty)
                    {
                        m_Reader.ReadEndElement();
                    }
                    else
                    {
                        m_Reader.Read();
                    }


                    return(retvalue);
                }
            }
            else
            {
                throw new ApplicationException(string.Format("Unable to deserialize element at line {0}, position {1}, Type attribute missing!", m_Reader.LineNumber, m_Reader.LinePosition));
            }
        }
        public void AddBaseValueStandalone(string name, object o, System.Type basetype)
        {
            IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetype);

            if (null == ss)
            {
                throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
            }
            else
            {
                m_Writer.WriteStartElement(name);
                m_Writer.WriteAttributeString("Type", m_SurrogateSelector.GetFullyQualifiedTypeName(basetype));
                ss.Serialize(o, this);
                m_Writer.WriteEndElement();
            }
        }
        public void AddValue(string name, object o)
        {
            IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(o.GetType());

            if (null == ss)
            {
                throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", o.GetType()));
            }
            else
            {
                PushNodeStack();
                m_CurrentNode = m_Doc.CreateElement(name);
                XmlAttribute typeattr = m_Doc.CreateAttribute("Type");
                typeattr.InnerText = m_SurrogateSelector.GetFullyQualifiedTypeName(o.GetType());
                m_CurrentNode.Attributes.Append(typeattr);

                ss.Serialize(o, this);
                FinishCurrentNode();
            }
        }
 public void GetBaseValueEmbedded(object instance, System.Type basetype, object parent)
 {
     if ("BaseType" == CurrentElementName)
     {
         string basetypestring         = m_Reader.ReadElementString();
         IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetypestring);
         if (null == ss)
         {
             throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
         }
         ss.Deserialize(instance, this, parent);
     }
     else
     {
         IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(basetype);
         if (null == ss)
         {
             throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", basetype));
         }
         ss.Deserialize(instance, this, parent);
     }
 }
 public void AddValue(string name, object o)
 {
     if (null != o)
     {
         IXmlSerializationSurrogate ss = m_SurrogateSelector.GetSurrogate(o.GetType());
         if (null == ss)
         {
             throw new ArgumentException(string.Format("Type {0} has no XmlSerializationSurrogate to get serialized", o.GetType()));
         }
         else
         {
             m_Writer.WriteStartElement(name);
             m_Writer.WriteAttributeString("Type", m_SurrogateSelector.GetFullyQualifiedTypeName(o.GetType()));
             ss.Serialize(o, this);
             m_Writer.WriteEndElement();
         }
     }
     else // o is null, we add only an empty element
     {
         m_Writer.WriteStartElement(name);
         m_Writer.WriteAttributeString("Type", "UndefinedValue");
         m_Writer.WriteEndElement();
     }
 }
Beispiel #14
0
		/// <summary>
		/// Adds a surrogate for the type <code>type</code>.
		/// </summary>
		/// <param name="type">The type for which the surrogate is added.</param>
		/// <param name="version">The version of the surrogate (higher version numbers mean more recent versions).</param>
		/// <param name="surrogate">The surrogate used to serialize/deserialize the type.</param>
		public void AddSurrogate(System.Type type, int version, IXmlSerializationSurrogate surrogate)
		{
			// if this attribute cares about a currently existing type,
			// consider the highest value of version among all attributes
			// which care for the same type as the current version of that type
			AddTypeAndVersionIfHigher(type, version, surrogate);

			m_Surrogates[GetFullyQualifiedTypeName(type, version)] = surrogate;
		}
Beispiel #15
0
		protected void AddTypeAndVersionIfHigher(System.Type type, int version, IXmlSerializationSurrogate surrogate)
		{
			int storedversion = m_Versions.ContainsKey(type) ? (int)m_Versions[type] : int.MinValue;

			if (version > storedversion)
			{
				m_Versions[type] = version;
				m_Surrogates[type] = surrogate;
			}
		}
Beispiel #16
0
		/// <summary>
		/// Adds a surrogate for the type specified in the XmlSerializationForAttribute.
		/// </summary>
		/// <param name="attr">The attribute used to describe the type this surrogate is intended for.</param>
		/// <param name="surrogate">The surrogate used to serialize/deserialize the type.</param>
		public void AddSurrogate(XmlSerializationSurrogateForAttribute attr, IXmlSerializationSurrogate surrogate)
		{
			if (null != attr.SerializationType)
				AddSurrogate(attr.SerializationType, attr.Version, surrogate);
			else
				AddSurrogate(attr.AssemblyName, attr.TypeName, attr.Version, surrogate);
		}
Beispiel #17
0
		/// <summary>
		/// Adds a surrogate for the type specified by assembly name, full type name, and version.
		/// </summary>
		/// <param name="assemblyname">The short name of the assembly.</param>
		/// <param name="typename">The fully qualified type name.</param>
		/// <param name="version">The version.</param>
		/// <param name="surrogate">The surrogate which is responsible to deserialize the type.</param>
		public void AddSurrogate(string assemblyname, string typename, int version, IXmlSerializationSurrogate surrogate)
		{
			m_Surrogates[assemblyname + "," + typename + "," + version] = surrogate;
		}
Beispiel #18
0
 /// <summary>
 /// Adds a surrogate for the type specified by assembly name, full type name, and version.
 /// </summary>
 /// <param name="assemblyname">The short name of the assembly.</param>
 /// <param name="typename">The fully qualified type name.</param>
 /// <param name="version">The version.</param>
 /// <param name="surrogate">The surrogate which is responsible to deserialize the type.</param>
 public void AddSurrogate(string assemblyname, string typename, int version, IXmlSerializationSurrogate surrogate)
 {
     _surrogates[assemblyname + "," + typename + "," + version] = surrogate;
 }