Hello,
I am new to your forum, and thought I would try my question here as I see this is a very active forum with honest answers!
Not very sure I worded my question correctly, and I'm not too sure I really know how to ask it...:shame:
So I will ask by demonstration. See below:
I have the following 3 classes.
So Now, in my application, I use the following:
This seems very redundant to me...
Is there a way I could simplify so that Class C could get the properties from the parent class.
For Example:
I am new to your forum, and thought I would try my question here as I see this is a very active forum with honest answers!
Not very sure I worded my question correctly, and I'm not too sure I really know how to ask it...:shame:
So I will ask by demonstration. See below:
I have the following 3 classes.
C#:
public class A
{
public string Name { get; set; }
public string Address { get; set; }
public List<B> Commands { get; set; }
public C Api = new C();
}
public class B
{
public string Name { get; set; }
public string Value { get; set; }
}
public class C
{
public int Port { get; set; }
public void SendCommand(A Parent, B Command)
{
APISend(Parent.Address, Command.Value, this.Port)
}
}
C#:
class Program
{
static void Main(string[] args)
{
A MyNewDevice = new A();
Populate(MyNewDevice); // retrieves and sets the Name and Address Properties
GetCommands(MyNewDevice); // retrieves and populates the List of Commands
MyNewDevice.Api.Port = 8080;
MyNewDevice.Api.SendCommand(MyNewDevice, MyNewDevice.Commands[1]);
}
}
Is there a way I could simplify so that Class C could get the properties from the parent class.
For Example:
C#:
public class C
{
public int Port { get; set; }
public void SendCommand( B Command)
{
APISend(A.Address, Command.Value, this.Port)
}
}
C#:
MyNewDevice.Api.SendCommand(Commands[1]);