Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 强制使用特定的xml对象序列化格式_C#_Xml - Fatal编程技术网

C# 强制使用特定的xml对象序列化格式

C# 强制使用特定的xml对象序列化格式,c#,xml,C#,Xml,我正在我的一个对象上使用C#序列化: StringWriter outStream = new StringWriter(); XmlSerializer s = new XmlSerializer(obj.GetType()); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); s.Serialize(outStream, obj, ns); string xml = outStream.ToS

我正在我的一个对象上使用C#序列化:

   StringWriter outStream = new StringWriter();
   XmlSerializer s = new XmlSerializer(obj.GetType());
   XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
   s.Serialize(outStream, obj, ns);
   string xml = outStream.ToString();
目标是:

public class Points
{
    [System.Xml.Serialization.XmlAttribute]
    public string Type;
    public double Number;
}
My
Points
类正被另一个程序使用,该程序的格式为:

 <Points Type="Credit">123</Points>
123
我正在努力工作,如果我可以使用任何属性来强制这种格式


谢谢

我认为您需要在数字字段上使用
[System.Xml.Serialization.XmlText]
属性,就像您在类型上使用
xmltribute
一样:

public class Points
{
    [System.Xml.Serialization.XmlAttribute]
    public string Type;
    [System.Xml.Serialization.XmlText]
    public double Number;
}
请参阅此线程: