How to get enum as parameter thru interface
-
I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types
public enum Mode
{
Off = 0,
On1 = 1,
On2 = 2
}and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:
int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);
So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:
result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);
My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.
-
I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types
public enum Mode
{
Off = 0,
On1 = 1,
On2 = 2
}and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:
int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);
So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:
result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);
My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.
If the existing projects don't reference each other then the only other way is to create another common project (dll class library), put any common objects in there and reference the new project (after building) in the existing ones
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types
public enum Mode
{
Off = 0,
On1 = 1,
On2 = 2
}and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:
int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);
So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:
result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);
My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.
MichCl wrote:
class ... to put the Mode definition in
An enumeration is a type and doesn't need to be in a class. You could put the enumeration and interface definition in their own project/DLL and reference it from the others, but generally a DLL should hold more than just those two things.