c# XML 序列化为元素赋值

c# XML serialization assigning value to element

我正在努力让我的 XML 看起来像下面这样

<Assets>
  <Asset id="" Type="" name="" filename="">filepath</Asset>  
  <Asset id="" Type="" name="" filename="">filepath</Asset>            
</Assets>

我目前拥有的是

public class Main
{    
    public List<Asset> Assets { get; set; }
}

public class Asset
{
    [XmlAttribute(AttributeName = "id")]
    public string Id { get; set; }

    [XmlAttribute(AttributeName = "Type")]
    public string Type { get; set; }

    [XmlAttribute(AttributeName = "name")]
    public string Name { get; set; }

    [XmlAttribute(AttributeName = "filename")]
    public string FileName { get; set; }

    public string FilePath { get; set; }
}

Class Main 并不重要,这是一个较大对象的一小段。

我遇到的问题是让文件路径成为资产元素的值

在当前状态下 XML 看起来像

<Assets>
  <Asset id="" Type="" name="" filename="">
    <FilePath>filepath</FilePath>
  </Asset>
  <Asset id="" Type="" name="" filename="">
    <FilePath>filepath</FilePath>
  </Asset>
</Assets>

尝试 XmlTextAttribute:

[XmlText]
public string FilePath { get; set; }