Reputation: 390
class Section
{
public string Name;
public List<Option> Options;
public class Option
{
public string Name;
public string Value;
public string Path
{
get { return "SectionName.OptionName=Value"; }
}
}
}
In other words, I would like to have access to members of Section from Option, which will always be used as a list. What is an elegant way to implement this?
Upvotes: 1
Views: 78
Reputation:
An Option
needs a reference to its Section
:
class Section
{
public string Name;
public List<Option> Options;
public class Option
{
public Section MySection { get; private set; }
public string Name;
public string Value;
public string Path
{
get { return string.Format("{0}.{1}={2}", this.MySection.Name, this.Name, this.Value); }
}
public Option(Section mySection)
{
this.MySection = mySection;
}
}
}
Upvotes: 4