I have two classes:
public class PageMeta
{
public PageMeta() { }
public string DataSource { get; set; }
public string TopicID { get; set; }
public string Title { get; set; }
}
public PersonViewModel()
{
PageMeta = new PageMeta
{
Title = "Test"
};
public PageMeta PageMeta { get; set; }
}
Using the following code to create these:
var r = new PersonViewModel();
r.PageMeta.DataSource="abc";
r.PageMeta.TopicID="def";
In real life my classes are more complicated and this is just an example. What I would like to do is to combine the creation of the PersonViewModel with the setting up of the DataSource and TopicID.
var r = new PersonViewModel {
PageMeta.DataSource="abc";
PageMeta.TopicID="def";
}
Is there any way that this could be done in C# ?
Yes.