سلام بر تمامی برنامه نویسان عزیز 😉 در این مطلب کد استفاده از XmlAttributeOverrides با XmlSerializer در سی شارپ را آماده کردم. امیدوارم که این کد برای شما مفید باشد.
کد استفاده از XmlAttributeOverrides با XmlSerializer در سی شارپ :
using System;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public override string ToString()
{
return string.Format("{0} {1}\nEmail: {2}",FirstName, LastName, EmailAddress);
}
}
public class Tester
{
static void Main()
{
Customer c1 = new Customer{
FirstName = "A",
LastName = "G",
EmailAddress = "o@a.com"
};
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
Type customerType = typeof(Customer);
foreach (PropertyInfo prop in customerType.GetProperties())
{
XmlAttributes attrs = new XmlAttributes();
attrs.XmlAttribute = new XmlAttributeAttribute();
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public override string ToString()
{
return string.Format("{0} {1}\nEmail: {2}",FirstName, LastName, EmailAddress);
}
}
public class Tester
{
static void Main()
{
Customer c1 = new Customer{
FirstName = "A",
LastName = "G",
EmailAddress = "o@a.com"
};
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
Type customerType = typeof(Customer);
foreach (PropertyInfo prop in customerType.GetProperties())
{
XmlAttributes attrs = new XmlAttributes();
attrs.XmlAttribute = new XmlAttributeAttribute();