我有这个c#对象
public class UserRoleAndGroupData
{
public Guid RoleId { get; set; }
public string RoleName { get; set; }
public int UserIntID { get; set; }
}
并希望将其转换为xml,如下所示 -
<add>
<doc>
<field name="RoleName">MyRole1</field>
<field name="RoleID">123</field>
<field name="UserIntId">567</field>
<doc>
</add>
答案 0 :(得分:0)
这个怎么样:
UserRoleAndGroupData u = new UserRoleAndGroupData();
...
string template = $@"<add>
<doc>
<field name="RoleName">{u.RoleName}</field>
<field name="RoleID">{u.RoleId}</field>
<field name="UserIntId">{u.UserIntID}</field>
<doc>
</add>";
...