Beispiel #1
0
        public static IntPtr CFTypeFromManagedType(object objVal)
        {
            if (objVal == null)
            {
                return(IntPtr.Zero);
            }
            IntPtr zero = IntPtr.Zero;
            Type   type = objVal.GetType();

            try
            {
                if (type == typeof(string))
                {
                    return(StringToCFString((string)objVal));
                }
                if (type == typeof(short) || type == typeof(ushort) || type == typeof(int) || type == typeof(uint) || type == typeof(long) || type == typeof(double) || type == typeof(float))
                {
                    return(CFNumberCreateNumbers(objVal));
                }
                if (type == typeof(bool))
                {
                    return(CFBoolean.GetCFBoolean(Convert.ToBoolean(objVal)));
                }
                if (type == typeof(DateTime))
                {
                    return(CFDateCreate(kCFAllocatorDefault, ((DateTime)objVal).Subtract(new DateTime(0x7d1, 1, 1, 0, 0, 0)).TotalSeconds));
                }
                if (type == typeof(byte[]))
                {
                    byte[] arr     = (byte[])objVal;
                    IntPtr ptrDest = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
                    zero = CFDataCreate(IntPtr.Zero, ptrDest, arr.Length);
                    return(zero);
                }
                if (type == typeof(object[]))
                {
                    return(CFArrayFromManageArray((object[])objVal));
                }
                if (type == typeof(ArrayList))
                {
                    return(CFArrayFromManageArrayList(objVal as ArrayList));
                }
                if (type == typeof(List <object>))
                {
                    return(CFArrayFromManageList(objVal as List <object>));
                }
                if (type == typeof(Dictionary <object, object>))
                {
                    zero = CFDictionaryFromManagedDictionary(objVal as Dictionary <object, object>);
                }
            }
            catch
            {
            }
            return(zero);
        }
Beispiel #2
0
 static CoreFoundation()
 {
     coreFundationDllIntPtr          = LoadLibrary("CoreFoundation.dll");
     kCFStreamPropertyDataWritten    = EnumToCFEnum("kCFStreamPropertyDataWritten");
     kCFTypeDictionaryKeyCallBacks   = ConstToCFConst("kCFTypeDictionaryKeyCallBacks");
     kCFTypeDictionaryValueCallBacks = ConstToCFConst("kCFTypeDictionaryValueCallBacks");
     kCFTypeArrayCallBacks           = ConstToCFConst("kCFTypeArrayCallBacks");
     kCFBooleanFalse = CFBoolean.GetCFBoolean(false);
     kCFBooleanTrue  = CFBoolean.GetCFBoolean(true);
 }