Search code examples
c#classmodeldatamodel

How to define a C# class model for these dataobjects


How can I define classes with properties where the following code would compile and be valid?

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";

Solution

  • This should do it:

    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; } 
    }