如何为这些数据对象定义C#类模型

时间:2020-03-28 07:33:11

标签: c# class model datamodel

如何定义具有以下代码可编译且有效的属性的类?

AtomEntry newPost = new AtomEntry();
newPost.Title.Text = "Marriage!";
newPost.Content = new AtomContent();
newPost.Content.Content = "<div xmlns='http://www.w3.org/1999/xhtml'>" +
  "<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" +
  "<p>He is the last man on earth I would ever desire to marry.</p>" +
  "<p>Whatever shall I do?</p>" +
  "</div>";
newPost.Content.Type = "xhtml";

1 个答案:

答案 0 :(得分:1)

这应该做到:

public class AtomEntry 
{ 
    public AtomContent Content { get; set; } 
    public Title Title { get; set; } 
}

public class AtomContent 
{ 
    public string Content { get; set; } 
    public string Type { get; set; } 
}

public class Title 
{ 
    public string Text { get; set; } 
}