If the number of tag values (PATHs) is small, then expose a method
for each of them to write the value. These would have the correct type of value parameter in the method signature. Don't expose the method that takes an arbitrary tag string.
E.g.:
const string PathA="A";
const string PathB="B";
public bool WritePathA(int value)
{
return WritePLC(PathA, value);
}
public bool WritePathB(string value)
{
return WritePLC(PathB, value);
}
private bool WritePLC(string tag, int value)
{
return true;
}
private bool WritePLC(string tag, string value)
{
return true;
}
This also assumes that the association between paths and value types is known at compile time. You implied this by what you wanted,
however you also stated
When i get the connection to PLC, I dynamically know the type of every tag
which implies to me that the type information is
not known until you're connected to the PLC. In this case it is obviously impossible for the compiler to know what will not be known until run time!