Atlanta .NET Regular Guys

Community Blog for two guys in Atlanta that focus on Microsoft and Community.

Quick About

This is the community blog for Brendon Schwartz and Matt Ranlett.  If you want to see their technical posts visit http://www.sharepointguys.com

Back To DevCow

Recent Posts

Tags

Email Notifications

    Archives

    Convert WMI CIMType to System.Type

    I was working with WMI yesterday to report information about a computer.  When trying to use the data in the application I ran into a problem that there is not an easy way to convert CIMTypes to System types.  If anyone has a suggestion let me know.  If not you can use my switch statement as a start for a Convert function.

                            private System.Type ConvertCimType(CimType ctValue)

                            {System.Type tReturnVal = null;

     

                                        switch(ctValue){

                                        case CimType.Boolean:

                                                    tReturnVal = typeof(System.Boolean) ;

                                                    break;

                                        case CimType.Char16:

                                                    tReturnVal = typeof(System.String);

                                                    break;

                                        case CimType.DateTime:

                                                    tReturnVal = typeof(System.DateTime);

                                                    break;

                                        case CimType.Object:

                                                    tReturnVal = typeof(System.Object);

                                                    break;

                                        case CimType.Real32:

                                                    tReturnVal = typeof(System.Decimal);

                                                    break;

                                        case CimType.Real64:

                                                    tReturnVal = typeof(System.Decimal);

                                                    break;

                                        case CimType.Reference:

                                                    tReturnVal = typeof(System.Object);

                                                    break;

                                        case CimType.SInt16:

                                                    tReturnVal = typeof(System.Int16);

                                                    break;

                                        case CimType.SInt32:

                                                    tReturnVal = typeof(System.Int32);

                                                    break;

                                        case CimType.SInt8:

                                                    tReturnVal = typeof(System.Int16);

                                                    break;

                                        case CimType.String:

                                                    tReturnVal = typeof(System.String);

                                                    break;

                                        case CimType.UInt16:

                                                    tReturnVal = typeof(System.UInt16);

                                                    break;

                                        case CimType.UInt32:

                                                    tReturnVal = typeof(System.UInt32);

                                                    break;

                                        case CimType.UInt64:

                                                    tReturnVal = typeof(System.UInt64);

                                                    break;

                                        case CimType.UInt8:

                                                    tReturnVal = typeof(System.UInt16);

                                                    break;

                                        }

                                             

                            return tReturnVal;

     

                            }


     

     —Brendon Schwartz

    Comments

    solutions for a better life said:

    That's a great point, yet stop and consider what would happen if suddenly you had the skills to influence and persuade anyone to do just about anything you wanted? How would you use those skills first?

    # April 26, 2008 2:53 AM

    airwave said:

    You can just use the cimType.GetType() method instead.

    # August 12, 2008 5:15 AM