When a new object of class Foo
is created, the constructor is supposed to create a new folder and a new file based on the object properties. But I get NullException (param: path2)
?
I found that the object properties has Null value when the constructor is called. But I gave the properties values when I created the object? What am I missing?
My Foo class:
public class Foo
{
public string Bar { get; set; }
public string Baz { get; set; }
public string Source { get { return Path.Combine(Qux, Baz, Bar); } }
private string Qux { get { return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } }
public Foo()
{
// Use property values to find or create Directory and File
if (!Directory.Exists(Path.Combine(Qux, Baz))) Directory.CreateDirectory(Path.Combine(Qux, Baz));
if (!File.Exists(Source)) File.Create(Source);
}
}
In my Main class:
// Create a new Foo object with following property values
Foo foo = new Foo { Baz = "corge", Bar = "grault" };