Esempio n. 1
0
        /// <summary>
        /// Converts a CFDictionary into a Dictionary (keys and values are object)
        /// </summary>
        public static Dictionary <object, object> ConvertCFDictionaryToDictionary(TypedPtr <CFDictionary> Dict)
        {
            // Get the raw key-value pairs
            int NumPairs = CFDictionaryGetCount(Dict);

            IntPtr [] Keys   = new IntPtr[NumPairs];
            IntPtr [] Values = new IntPtr[NumPairs];

            CoreImpl.CFDictionaryGetKeysAndValues((IntPtr)Dict, Keys, Values);

            // Convert each key and value to a managed type
            Dictionary <object, object> Result = new Dictionary <object, object>();

            for (int i = 0; i < NumPairs; ++i)
            {
                try
                {
                    Result.Add(ConvertArbitraryCFType(Keys[i]), ConvertArbitraryCFType(Values[i]));
                }
                catch (Exception)
                {
                    Console.WriteLine("Unable to properly convert dictionary");
                }
            }

            return(Result);
        }