Your IP : 216.73.216.48


Current Path : /hdd/hdd21/uploads/00c6aa1c629832457cd50f35cdae6841bf576089/
Upload File :
Current File : //hdd/hdd21/uploads/00c6aa1c629832457cd50f35cdae6841bf576089/helper.txt

public static string SerializeObject<T>(T values, string rootName, bool omitXmlDeclaration = false,
        bool indentXml = true)
        {
            string xml = string.Empty;

            var serializer = new XmlSerializer(typeof(T), new XmlRootAttribute(rootName));

            var settings = new XmlWriterSettings()
            {
                Indent = indentXml,
                OmitXmlDeclaration = omitXmlDeclaration
            };

            XmlSerializerNamespaces @namespace = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });

            using (var stream = new StringWriter())
            using (var writer = XmlWriter.Create(stream, settings))
            {
                serializer.Serialize(writer, values, @namespace);
                xml = stream.ToString();
            }

            return xml;
        }

-------------------------------------------------------------------------------------------------------------------------

private static bool IsValid(object entity)
        {
            System.ComponentModel.DataAnnotations.ValidationContext validatorContext = new System.ComponentModel.DataAnnotations.ValidationContext(entity);
            IList<ValidationResult> validationResult = new List<ValidationResult>();

            bool isValid = Validator.TryValidateObject(entity, validatorContext, validationResult, true);

            return isValid;
        }

---------------------------------------------------------------------------------------------------------------------------

XmlSerializer serializer = new XmlSerializer(typeof(ImportPurchase[]), new XmlRootAttribute("Purchases"));
ImportPurchase[] purchasesDto = (ImportPurchase[])serializer.Deserialize(new StringReader(xmlString));