I have the following C# classes:
public class Locales
{
public Region region { get; set; }
public Buttons buttons { get; set; }
public Fields fields { get; set; }
}
public class Region
{
public Center center { get; set; }
public East east { get; set; }
}
public class Center
{
public string title { get; set; }
}
public class East
{
public string title { get; set; }
}
public class Buttons
{
public string save { get; set; }
}
public class Fields
{
public Labels labels { get; set; }
}
public class Labels
{
public string firstName { get; set; }
public string lastName { get; set; }
public string chooseLocale { get; set; }
}
To sum up, Locales has Region, Buttons and Fields. Region has Center and East. Center and East have property title. Fields has Labels which has properties firstName, lastName and chooseLocale.
In a method (called GetLocale) I have the following code:
Locale englishLang = new Locale();
englishLang.region.center.title = "Center Region";
englishLang.region.east.title = "East Region - Form";
englishLang.buttons.save = "Save";
englishLang.fields.labels.firstName = "First Name";
englishLang.fields.labels.lastName = "Last Name";
englishLang.fields.labels.chooseLocale = "Choose Your Locale";
When I run the code, a "NullReferenceException was unhandled by user code" is thrown at the line : englishLang.region.center.title = "Center Region";
Am I doing something wrong in the way I have set the properties title, save, firstName, lastName and chooseLocale?
I tried adding the following block of code after Locale englishLang = new Locale();
and before englishLang.region.center.title = "Center Region";
but I still get the error message.
Region region = new Region();
Center center = new Center();
East east = new East();
Buttons buttons = new Buttons();
Fields fields = new Fields();
Labels labels = new Labels();
What am I doing wrong?