NetDataContractSerializer.cs :  » 2.6.4-mono-.net-core » System.Runtime » System » Runtime » Serialization » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » 2.6.4 mono .net core » System.Runtime 
System.Runtime » System » Runtime » Serialization » NetDataContractSerializer.cs
//
// NetDataContractSerializer.cs
//
// Author:
//  Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Xml.Schema;

using QNameSystem.Xml.XmlQualifiedName;

namespace System.Runtime.Serialization{
  public sealed class NetDataContractSerializer
    : XmlObjectSerializer, IFormatter
  {
    const string xmlns = "http://www.w3.org/2000/xmlns/";
    const string default_ns = "http://schemas.datacontract.org/2004/07/";

    // This is only for compatible mode.
    StreamingContext context;
//    KnownTypeCollection known_types;
//    IDataContractSurrogate surrogate;

    SerializationBinder binder;
    ISurrogateSelector selector;

    int max_items = 0x10000; // FIXME: could be from config.
    bool ignore_extensions;
    FormatterAssemblyStyle ass_style;

    XmlDictionaryString root_name, root_ns;

    public NetDataContractSerializer ()
    {
    }

    public NetDataContractSerializer (StreamingContext context)
    {
      this.context = context;
    }

    public NetDataContractSerializer (string rootName,
      string rootNamespace)
    {
      FillDictionaryString (rootName, rootNamespace);
    }

    public NetDataContractSerializer (XmlDictionaryString rootName,
      XmlDictionaryString rootNamespace)
    {
      if (rootName == null)
        throw new ArgumentNullException ("rootName");
      if (rootNamespace == null)
        throw new ArgumentNullException ("rootNamespace");
      root_name = rootName;
      root_ns = rootNamespace;
    }

    public NetDataContractSerializer (StreamingContext context, 
      int maxItemsInObjectGraph,
      bool ignoreExtensibleDataObject,
      FormatterAssemblyStyle assemblyFormat,
      ISurrogateSelector surrogateSelector)
    {
      this.context = context;
      max_items = maxItemsInObjectGraph;
      ignore_extensions = ignoreExtensibleDataObject;
      ass_style = assemblyFormat;
      selector = surrogateSelector;
    }

    public NetDataContractSerializer (
      string rootName, string rootNamespace,
      StreamingContext context, 
      int maxItemsInObjectGraph,
      bool ignoreExtensibleDataObject,
      FormatterAssemblyStyle assemblyFormat,
      ISurrogateSelector surrogateSelector)
      : this (context, maxItemsInObjectGraph,
        ignoreExtensibleDataObject, assemblyFormat,
        surrogateSelector)
    {
      FillDictionaryString (rootName, rootNamespace);
    }

    public NetDataContractSerializer (
      XmlDictionaryString rootName,
      XmlDictionaryString rootNamespace,
      StreamingContext context,
      int maxItemsInObjectGraph,
      bool ignoreExtensibleDataObject,
      FormatterAssemblyStyle assemblyFormat,
      ISurrogateSelector surrogateSelector)
      : this (context, maxItemsInObjectGraph,
        ignoreExtensibleDataObject, assemblyFormat,
        surrogateSelector)
    {
      if (rootName == null)
        throw new ArgumentNullException ("rootName");
      if (rootNamespace == null)
        throw new ArgumentNullException ("rootNamespace");
      root_name = rootName;
      root_ns = rootNamespace;
    }

    void FillDictionaryString (string rootName, string rootNamespace)
    {
      if (rootName == null)
        throw new ArgumentNullException ("rootName");
      if (rootNamespace == null)
        throw new ArgumentNullException ("rootNamespace");
      XmlDictionary d = new XmlDictionary ();
      root_name = d.Add (rootName);
      root_ns = d.Add (rootNamespace);
    }

    public FormatterAssemblyStyle AssemblyFormat {
      get { return ass_style; }
      set { ass_style = value; }
    }

    public SerializationBinder Binder {
      get { return binder; }
      set { binder = value; }
    }

    public bool IgnoreExtensionDataObject {
      get { return ignore_extensions; }
    }

    public ISurrogateSelector SurrogateSelector {
      get { return selector; }
      set { selector = value; }
    }

    public StreamingContext Context {
      get { return context; }
      set { context = value; }
    }

    public int MaxItemsInObjectGraph {
      get { return max_items; }
    }

    public object Deserialize (Stream stream)
    {
      return ReadObject (stream);
    }

    [MonoTODO]
    public override bool IsStartObject (XmlDictionaryReader reader)
    {
      throw new NotImplementedException ();
    }

    public override object ReadObject (XmlDictionaryReader reader, bool readContentOnly)
    {
      /*
      int startTypeCount = known_types.Count;

      object ret = XmlFormatterDeserializer.Deserialize (
        // FIXME: remove this second param.
        reader, null, known_types, surrogate, readContentOnly);

      if (!readContentOnly && reader.NodeType == XmlNodeType.EndElement)
        reader.Read ();

      // remove temporarily-added known types for
      // rootType and object graph type.
      while (known_types.Count > startTypeCount)
        known_types.RemoveAt (startTypeCount);

      return ret;
      */
      throw new NotImplementedException ();
    }

    public void Serialize (Stream stream, Object graph)
    {
      using (XmlWriter w = XmlWriter.Create (stream)) {
        WriteObject (w, graph);
      }
    }

    [MonoTODO ("support arrays; support Serializable; support SharedType; use DataContractSurrogate")]
    /*
      when writeContentOnly is true, then the input XmlWriter
      must be at element state. This is to write possible
      xsi:nil.

      rootType determines the top-level element QName (thus
      it is ignored when writeContentOnly is true).

      preserveObjectReferences indicates that whether the
      output should contain ms:Id or not.
      (http://schemas.microsoft.com/2003/10/Serialization/)
    */
    public override void WriteObjectContent (
      XmlDictionaryWriter writer, object graph)
    {
      /*
      int startTypeCount = known_types.Count;

      string ns = default_ns;

      //writer.WriteAttributeString ("xmlns", "i", xmlns, XmlSchema.InstanceNamespace);
      //writer.WriteAttributeString ("xmlns", "x", xmlns, XmlSchema.Namespace);
      if (ns != null)
        writer.WriteAttributeString ("xmlns", xmlns, ns);

      XmlFormatterSerializer.Serialize (writer, graph,
        known_types,
        ignore_extensions, max_items);

      // remove temporarily-added known types for
      // rootType and object graph type.
      while (known_types.Count > startTypeCount)
        known_types.RemoveAt (startTypeCount);
      */
      throw new NotImplementedException ();
    }

    public override void WriteStartObject (
      XmlDictionaryWriter writer, object graph)
    {
      /*
      Type rootType = graph.GetType ();
      known_types.Add (rootType);
      SerializationMap map =
        known_types.FindUserMap (rootType);
      QName name = map != null ? map.XmlName :
        KnownTypeCollection.GetPredefinedTypeName (rootType);
      writer.WriteStartElement (
        name.Name, name.Namespace);
      */
      throw new NotImplementedException ();
    }

    public override void WriteEndObject (XmlDictionaryWriter writer)
    {
      writer.WriteEndElement ();
    }
  }
}
#endif
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.