.XmlSerializers.dll how to use it - confused examples over the Internet

I am new to C #. I started using SGEN generated by XmlSerializers.dll and I am really confused right now. Despite the fact that I can not find a single true step-by-step tutorial on how to use it correctly, I am also confused by different tips.

I have read many SGEN articles and am still not sure how to use the generated library in my project.

Can someone who has a practice with real coding explain to me once and for all the correct way to use it?

I thought I figured out how to use it, but yesterday I found this tutorial: http://www.dotnetfunda.com/articles/article1105-optimized-way-of-xml-serialization-using-sgen-utility-.aspx

The guy added .XmlSerializers.dll to his projects and uses this code for Serialize:

static string SerializebySGEN()
{
  Person p = new Person();
  p.Age = 29;
  p.Name = "Satya Narayan Sahoo";
  StringBuilder buildr = new StringBuilder();
  StringWriter writr = new System.IO.StringWriter(buildr);
  PersonSerializer mySerialzer = new PersonSerializer();
  mySerialzer.Serialize(writr, p);
  string str = writr.ToString();
  return str;
}

PersonSerializer mySerialzer = new PersonSerializer ();

but in stackoverflow in the past, someone wrote to my other question related to XmlSerializers:

Adding a link is not required; Xml serialization always tries Assembly.Load () on .XmlSerializers.dll anyway. > In addition, you will never refer to the generated XmlSerializationWriterXxx and the XmlSerializationReaderXxx classes directly in your code.

So who is right? Can any of the practitioners tell me how I should use this generated SGEN library with my project and code? I really want to use it in a good way! :)

: , , - , ? :)

Edit2: Serializable Classes (MySerializableClass), SGEN MySerializableClassSerializer. ? ( , PLZ ;))

        /// <summary>
        /// Deserializes the specified XML source into object using SGEN generated class.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xmlSource">The XML source.</param>
        /// <param name="isFile">if set to <c>true</c> the the source is a text File else it is a XML String.</param>
        /// <returns>Return object with deserialized XML</returns>
        public static MySerializableClass MySerializableClassSgenDeserialize(string xmlSource, bool isFile = true)
        {
            MySerializableClass data = new MySerializableClass();

            if (isFile)
            {
                using (TextReader textReader = new StreamReader(xmlSource))
                {
                    MySerializableClassSerializer xSerializer = new MySerializableClassSerializer();
                    data = (MySerializableClass)xSerializer.Deserialize(textReader);
                }
            }
            else
            {
                using (StringReader xmlText = new StringReader(xmlSource))
                {
                    MySerializableClassSerializer xSerializer = new MySerializableClassSerializer();
                    data = (MySerializableClass)xSerializer.Deserialize(xmlText);
                }
            }

            return data;
        }
+3
1

" " - .

( ) , . , , , , , .

, - .

0

All Articles