Example #1
0
        public static Object GetTypedObjectFromString(WbemCimtypeEnum cimType, String strValue)
        {
            switch (cimType)
            {
            case (WbemCimtypeEnum.wbemCimtypeBoolean):
            {
                Boolean bValue = Boolean.FromString(strValue);
                return(bValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeChar16):
            {
                Char charValue = Char.FromString(strValue);
                return(charValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeDatetime):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeObject):
            {
                //VT_UNKNOWN
                //what's the format of strValue?
                //thios wouldn't work until there is a way to invoke custom type converters and editors
                return(null);
            }

            case (WbemCimtypeEnum.wbemCimtypeReal32):
            {
                Single retValue = Single.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeReal64):
            {
                Double retValue = Double.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeReference):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint16):
            {
                Int16 retValue = Int16.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint32):
            {
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint64):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeSint8):
            {
                //NOTE that wbemCimtypeSint8 get expanded to VT_I2 in automation layer
                Int16 retValue = Int16.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeString):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint16):
            {
                //NOTE that wbemCimtypeUint16 gets expanded to VT_I4 in automation layer
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint32):
            {
                Int32 retValue = Int32.FromString(strValue);
                return(retValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint64):
            {
                return(strValue);
            }

            case (WbemCimtypeEnum.wbemCimtypeUint8):
            {
                Byte retVal = Byte.FromString(strValue);
                return(retVal);
            }

            default:
                return(strValue);
            }
        }