I have a problem with my radio buttons. What I’m doing is I create a customer object and at the same time I want to set one bool property of each radio button in the customer base class. The error message I get is “StackOverflowException Was Unhandeled”. The error is pointing at this “IsClient = value;” in the CustomerType class.
Here is where I create the Customer object (inside CustomerForm.cs)
m_customer = new Customer(radioClient.Checked, radioProspect.Checked, radioCompany.Checked, radioPrivate.Checked);
public class Customer : CustomerType
{
private Contact m_contact;
private string m_id;
public Customer()
{
m_id = string.Empty;
}
public Customer(bool client, bool prospect, bool company, bool priv)
{
base.IsClient = client;
base.IsProspect = prospect;
base.IsCompany = company;
base.IsPrivate = priv;
m_id = string.Empty;
}
public Customer(Contact contactData)
{ m_contact = contactData; }
public Customer(string id, Contact contact)
{
m_id = id;
m_contact = contact;
}
public Contact ContactData
{
get { return m_contact; }
set {
if (value != null)
m_contact = value;
}
}
public string Id
{
get { return m_id; }
set { m_id = value; }
}
public override string ToString()
{
return m_contact.ToString();
}
}
public class CustomerType
{
public bool IsClient
{
get { return IsClient; }
set { IsClient = value; }
}
public bool IsCompany
{
get { return IsCompany; }
set { IsCompany = value; }
}
public bool IsPrivate
{
get { return IsPrivate; }
set { IsPrivate = value; }
}
public bool IsProspect
{
get { return IsProspect; }
set { IsProspect = value; }
}
}
All the properties in your
CustomerTypeare recursive – they blow the stack.Take a look at this:
When you try to get the value of the
IsClientproperty, you then try to get the value of theIsClientproperty. Which then tries to get the value of theIsClientproperty …Either implement these as automatically implemented properties:
Or have a proper backing field: