Esempio n. 1
0
        /// <summary>
        /// Converts an arbitrary CFNumber to a double
        /// </summary>
        public static double ConvertCFNumber(TypedPtr <CFNumber> Number)
        {
            CFNumberType TypeID = CoreImpl.CFNumberGetType((IntPtr)Number);

            switch (TypeID)
            {
            case CFNumberType.kCFNumberFloat32Type:
            case CFNumberType.kCFNumberFloatType:
            {
                float Result;
                CoreImpl.CFNumberGetValue((IntPtr)Number, CFNumberType.kCFNumberFloat32Type, out Result);
                return(Result);
            }

            case CFNumberType.kCFNumberFloat64Type:
            case CFNumberType.kCFNumberDoubleType:
            case CFNumberType.kCFNumberCGFloatType:
            {
                double Result;
                CoreImpl.CFNumberGetValue((IntPtr)Number, CFNumberType.kCFNumberFloat64Type, out Result);
                return(Result);
            }

            case CFNumberType.kCFNumberSInt8Type:
            case CFNumberType.kCFNumberSInt16Type:
            case CFNumberType.kCFNumberSInt32Type:
            case CFNumberType.kCFNumberCharType:
            case CFNumberType.kCFNumberShortType:
            case CFNumberType.kCFNumberIntType:
            case CFNumberType.kCFNumberLongType:
            case CFNumberType.kCFNumberCFIndexType:
            {
                int Result;
                CoreImpl.CFNumberGetValue((IntPtr)Number, CFNumberType.kCFNumberIntType, out Result);
                return(Result);
            }

            case CFNumberType.kCFNumberSInt64Type:
            case CFNumberType.kCFNumberLongLongType:
            case CFNumberType.kCFNumberNSIntegerType:
            {
                Int64 Result;
                CoreImpl.CFNumberGetValue((IntPtr)Number, CFNumberType.kCFNumberSInt64Type, out Result);
                return(Result);
            }

            default:
                return(0.0);
            }
        }