Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XMLSerializer

XMLSerializer

Scheduled Pinned Locked Moved C#
visual-studiocomsysadminxmljson
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George_George
    wrote on last edited by
    #1

    Hello everyone, Two questions about XMLSerializer. http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(VS.80).aspx 1. It is mentioned -- "To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types." What means the assemblies? 2. For the following sample, why creates two XMLSerializer instances, one is s and the other is ser?

    Hashtable serializers = new Hashtable();

    // Use the constructor that takes a type and XmlRootAttribute.
    XmlSerializer s = new XmlSerializer(typeof(MyClass), myRoot);

    // Implement a method named GenerateKey that creates unique keys
    // for each instance of the XmlSerializer. The code should take
    // into account all parameters passed to the XmlSerializer
    // constructor.
    object key = GenerateKey(typeof(MyClass), myRoot);

    // Check the local cache for a matching serializer.
    XmlSerializer ser = (XmlSerializer)serializers[key];
    if (ser == null)
    {
    ser = new XmlSerializer(typeof(MyClass), myRoot);
    // Cache the serializer.
    serializers[key] = ser;
    }
    else
    {
    // Use the serializer to serialize, or deserialize.
    }

    thanks in advance, George

    L N 2 Replies Last reply
    0
    • G George_George

      Hello everyone, Two questions about XMLSerializer. http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(VS.80).aspx 1. It is mentioned -- "To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types." What means the assemblies? 2. For the following sample, why creates two XMLSerializer instances, one is s and the other is ser?

      Hashtable serializers = new Hashtable();

      // Use the constructor that takes a type and XmlRootAttribute.
      XmlSerializer s = new XmlSerializer(typeof(MyClass), myRoot);

      // Implement a method named GenerateKey that creates unique keys
      // for each instance of the XmlSerializer. The code should take
      // into account all parameters passed to the XmlSerializer
      // constructor.
      object key = GenerateKey(typeof(MyClass), myRoot);

      // Check the local cache for a matching serializer.
      XmlSerializer ser = (XmlSerializer)serializers[key];
      if (ser == null)
      {
      ser = new XmlSerializer(typeof(MyClass), myRoot);
      // Cache the serializer.
      serializers[key] = ser;
      }
      else
      {
      // Use the serializer to serialize, or deserialize.
      }

      thanks in advance, George

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      George_George wrote:

      What means the assemblies?

      Are you kidding? http://www.google.com/search?hl=en&q=MSDN+%22What+is+an+assembly%22&btnG=Search[^]

      George_George wrote:

      For the following sample, why creates two XMLSerializer instances, one is s and the other is ser?

      They are two different samples as discussed in the text preceding the sample code section of the documentation. See the text and the use of the word "otherwise".

      led mike

      G 1 Reply Last reply
      0
      • G George_George

        Hello everyone, Two questions about XMLSerializer. http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(VS.80).aspx 1. It is mentioned -- "To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types." What means the assemblies? 2. For the following sample, why creates two XMLSerializer instances, one is s and the other is ser?

        Hashtable serializers = new Hashtable();

        // Use the constructor that takes a type and XmlRootAttribute.
        XmlSerializer s = new XmlSerializer(typeof(MyClass), myRoot);

        // Implement a method named GenerateKey that creates unique keys
        // for each instance of the XmlSerializer. The code should take
        // into account all parameters passed to the XmlSerializer
        // constructor.
        object key = GenerateKey(typeof(MyClass), myRoot);

        // Check the local cache for a matching serializer.
        XmlSerializer ser = (XmlSerializer)serializers[key];
        if (ser == null)
        {
        ser = new XmlSerializer(typeof(MyClass), myRoot);
        // Cache the serializer.
        serializers[key] = ser;
        }
        else
        {
        // Use the serializer to serialize, or deserialize.
        }

        thanks in advance, George

        N Offline
        N Offline
        Nissim Salomon
        wrote on last edited by
        #3

        1.The XML Serializer creates an XML serialization assembly per type that you are trying to Serialize\DeSerialize. you can increase performance using precompiled serialization assembly that you are creating using the sgen.exe utility. 2.Sorry but i dont have a clue for this one.

        G 1 Reply Last reply
        0
        • N Nissim Salomon

          1.The XML Serializer creates an XML serialization assembly per type that you are trying to Serialize\DeSerialize. you can increase performance using precompiled serialization assembly that you are creating using the sgen.exe utility. 2.Sorry but i dont have a clue for this one.

          G Offline
          G Offline
          George_George
          wrote on last edited by
          #4

          Thanks nissims, 1. You mean CLR will create a new assembly (DLL/EXE) for each type I need to serialize, other than using existing CLR assembly (e.g. System.XML.dll)? For example, when I want to serialize type Foo, CLR will create something like FooSerialize.dll? 2. The additional dynamically created assembly will be deleted when I unload the Appdomain? And next time when I run my assembly again, each of the dynamically created assemblies will be created again? 3. My assembly will invoke the dynamically created assemblies to do serialize/deserialize? 4. "using precompiled serialization assembly that you are creating using the sgen.exe utility" -- do you have any samples or reference documents? regards, George

          1 Reply Last reply
          0
          • L led mike

            George_George wrote:

            What means the assemblies?

            Are you kidding? http://www.google.com/search?hl=en&q=MSDN+%22What+is+an+assembly%22&btnG=Search[^]

            George_George wrote:

            For the following sample, why creates two XMLSerializer instances, one is s and the other is ser?

            They are two different samples as discussed in the text preceding the sample code section of the documentation. See the text and the use of the word "otherwise".

            led mike

            G Offline
            G Offline
            George_George
            wrote on last edited by
            #5

            You misunderstand my points and my English is not good. :-) Any comments to? http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2550767[^] regards, George

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups