Reputation: 486
I am writing some generic classes that i'd like to use in some of my apps. For example this socket class:
public class jSocket
{
public class Server
{
public static _Settings Settings = new _Settings();
public class _Settings
{
private int _Listen;
public int Listen
{
get
{
return _Listen;
}
set
{
_Listen = value;
}
}
private int _Port;
public int Port
{
get
{
if (_Port == 0)
_Port = 1337;
return _Port;
}
set
{
_Port = value;
}
}
private IPEndPoint _localEndPoint;
public IPEndPoint localEndPoint
{
get
{
if(_localEndPoint == null)
_localEndPoint = new IPEndPoint(Tools.getLocalIPAddress(), Port);
return _localEndPoint;
}
set
{
_localEndPoint = value;
}
}
}
public void Start()
{
//Do work
}
}
Now in my application i instantiate the class:
jSocket.Server newServ = new jComp.jSocket.Server();
But why can't I access the Properties of Settings? What I want to do is this:
newServ.Settings.Port = 1001;
Do I need to write constructors for every field?
Upvotes: 0
Views: 518
Reputation: 101711
Setting
field is static
, you need to remove static
and make it an instance field.So then it will belong to your instance and you will be able to access it.
public _Settings Settings = new _Settings();
Upvotes: 1