I'll try and explain my problem.
I'm simulating an incoming event that in my application I get from a COM object. My problem is that I can't seem to figure out how to convert an object back to enum.
Here is my simulated event that I in real life receive through a COM object.
Expand|Select|Wrap|Line Numbers
- private void button1_Click(object sender, System.EventArgs e)
- {
- //atLocationType is of type enum
- atLocationType[] t = new atLocationType[3];
- t[0] = atLocationType.atLocationType_System900_Locator;
- t[1] = atLocationType.atLocationType_SystemDECT_Signpost;
- t[2] = atLocationType.atLocationType_Manual;
- object p = t;
- myalarm_OnAlarm(3, ref p);
- }
Expand|Select|Wrap|Line Numbers
- private void myalarm_OnAlarm(int NumberOfLocations, ref object LocationType)
- {
- //atLocationType is of type enum
- atLocationType tempLocationType;
- int i;
- Console.WriteLine (NumberOfLocations);
- for (i = 0; i < NumberOfLocations; i++)
- {
- tempLocationType = (ATOAC2Lib.atLocationType)((Object[])LocationType)[i];
- Console.WriteLine(tempLocationType);
- }
- }
Unable to cast object of type 'atLocationType[]' to type 'System.Object[]'.
If I use a String instead of an enum in both the event and the event handler everything works fine though.
Any idea about how I can get the enum value back from object?
Thanks