Exemplo n.º 1
0
        public override string ToString()
        {
            YAXSerializer serializer = new YAXSerializer(typeof(Envelope <TCustom>));
            var           doc        = serializer.SerializeToXDocument(this);

            doc.Root.ReplaceAttributes(doc.Root.Attributes()
                                       .OrderByDescending(attr => attr.Name.Namespace.NamespaceName));
            return("<?xml version=\"1.0\" encoding=\"GBK\"?>" +
                   doc.ToString(SaveOptions.DisableFormatting).Replace(" />", "/>"));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Convierte un objet a XDocument
 /// </summary>
 /// <typeparam name="T">tipo t</typeparam>
 /// <param name="obj">objeto a serializar</param>
 /// <returns>XDocument</returns>
 public static XDocument ObjetToXMLDocument <T>(T obj)
 {
     try
     {
         var serializer = new YAXSerializer(typeof(T));
         var xml        = serializer.SerializeToXDocument(obj);
         return(xml);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public void SerializeToElement(Dictionary <string, MyTask> tasksToSerialize, XElement elemToFill)
        {
            foreach (string taskPropName in tasksToSerialize.Keys)
            {
                MyTask task = tasksToSerialize[taskPropName];
                task.PropertyName = taskPropName;

                YAXSerializer serializer = new YAXSerializer(typeof(MyTask), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning);

                XElement   taskElement = serializer.SerializeToXDocument(task).Root;
                XAttribute ns          = taskElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "yaxlib");
                if (ns != null)
                {
                    ns.Remove();
                }

                elemToFill.Add(taskElement);
            }
        }
Exemplo n.º 4
0
        //---R

        #region YAX Serializer

        public static XElement Serialize_YAX(object obj)
        {
            YAXSerializer serializer = new YAXSerializer(obj.GetType(), YAXSerializationOptions.DontSerializeNullObjects);

            return(serializer.SerializeToXDocument(obj).Root);
        }