How to make a type safe wrapper around Variant values
问题 I'm working with a OPC Server control that stores data tags as variant types, described by System.Runtime.InteropServices.VarEnum . These types include the following, VT_BSTR (string), VT_I2 (short) and VT_I4 (long). All these values are stored by the server as objects and then I have to cast to the correct value when I fetch them. I know that I can do something like the following: object tagValue = (object)"testing"; //this would be returned from a function rather than created this way!! var