Here is the code that demonstrates my problem (All in the same namespace):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Fubar.BGroup.A = true;
}
public Foo Fubar = new Foo();
}
public class Foo
{
public Foo()
{
}
private BoolGroup bGroup = new BoolGroup();
public BoolGroup BGroup
{
get{ return this.bGroup; }
set
{
this.bGroup = value;
this.doSomething();
}
}
}
public class BoolGroup
{
public BoolGroup()
{
}
private bool a;
public bool A
{
get { return this.a; }
set { this.a = value; }
}
}
private void doSomething()
{
....
}
I will never get to doSomething() and I really want to. What am I doing wrong? The values will all get set properly, but I never seem to get into that the set part of BGroup.
Thanks
You never set
BGroupat all. The closest things you do areFubar.BGroup.A = trueandbGroup = new BoolGroup();.Fubar.BGroup.A = truegets theBGroupproperty, and sets theAproperty on theBoolGroupobject, it doesn’t set theBGroup.bGroup = new BoolGroup()sets the backing field of theBGroupproperty, which is why you get thatBoolGroupwhen you getBGroup, but it doesn’t go through the setter.If you want to use the setter, your
Fooclass should be like this: