So this particular topic has been beaten to death; but apparently my iteration is either not the method of choice or isn’t practical for implementation.
The goal is to create a Windows Form and a Web Form. Those two forms; set a property in a separate class. Then other classes reference the container; that way as the interface is changed the functionality will change without a lot of recoding.
Windows Form —> Container <— Web Form
Container –> Referenced by these: Class 1, Class 2, Class 3
I approached it like this:
Form:
private Some.Reference.ToClass.Container _container;
public void Method(Some.Reference.ToClass.Container Container)
{
_container = Container;
}
private void button_click(object sender, EventArgs e)
{
_container.Name = textbox.Text (or some other component)
}
Class: “Container”
public Name { get; set; }
Class or Form to Reference:
Class WhateverName
{
private string REFERENCE;
private Some.Reference.ToClass.Container _container;
public void Method(Some.Reference.ToClass.Container Container)
{
_container = Container;
}
public void NewMethod()
{
REFERENCE = _container.Name;
}
}
It continually doesn’t set; it states it’s a null object. What am I missing? Any help would be appreciated. Or even a nice tutorial for me to compare to learn; or find why it doesn’t work would be fine as well.
Based on the details provided; including the issue with the null value. I set a Constructor to automatically initialize based upon the change. Then just added some null reference check.
An example of this resolution:
Then in the other class; it references the Property; for it to be set. So to avoid it failing cause a value hasn’t been assigned yet or an instance hasn’t been created just added a null reference verification.