S
shapper
Hello,
I have a class as follows:
public class SupplierRepository : ISupplierRepository {
public String Path { get; set; }
private readonly XDocument context = XDocument.Load(Path);
public SupplierRepository(String path) {
Path = path;
}
}
I get the error:
A field initializer cannot reference the non-static field, method, or
property
I understand that I can make it work using:
public static String Path { get; set; }
But is this the way to do this?
Basically I need to define the path when I initialize a
SupplierRepository instance and then load the document to be used in
all the class methods ...
Thanks,
Miguel
I have a class as follows:
public class SupplierRepository : ISupplierRepository {
public String Path { get; set; }
private readonly XDocument context = XDocument.Load(Path);
public SupplierRepository(String path) {
Path = path;
}
}
I get the error:
A field initializer cannot reference the non-static field, method, or
property
I understand that I can make it work using:
public static String Path { get; set; }
But is this the way to do this?
Basically I need to define the path when I initialize a
SupplierRepository instance and then load the document to be used in
all the class methods ...
Thanks,
Miguel