示例#1
0
        private string CFNumber()
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(CFLibrary.CFNumberGetByteSize(typeRef));
            bool   scs    = CFLibrary.CFNumberGetValue(typeRef, CFLibrary.CFNumberGetType(typeRef), buffer);

            if (scs != true)
            {
                return(string.Empty);
            }
            int type = (int)CFLibrary.CFNumberGetType(typeRef);

            switch (type)
            {
            case 1:
                return(Marshal.ReadInt16(buffer).ToString());

            case 2:
                return(Marshal.ReadInt16(buffer).ToString());

            case 3:
                return(Marshal.ReadInt32(buffer).ToString());

            case 4:
                return(Marshal.ReadInt64(buffer).ToString());

            default:
                return(Enum.GetName(typeof(CFNumber.CFNumberType), type) + " is not supported yet!");
            }
        }
示例#2
0
        public override string ToString()
        {
            if (typeRef == IntPtr.Zero)
            {
                return(null);
            }
            switch (CFLibrary.CFGetTypeID(typeRef))
            {
            case _CFString:
                return(CFString());

            case _CFDictionary:
                return(CFPropertyList());

            case _CFArray:
                return(CFPropertyList());

            case _CFData:
                return(CFData());

            case _CFBoolean:
                return(CFBoolean());

            case _CFNumber:
                return(CFNumber());
            }
            return(null);
        }
示例#3
0
        private string CFString()
        {
            if (typeRef == IntPtr.Zero)
            {
                return(null);
            }

            string str;
            int    length = CFLibrary.CFStringGetLength(typeRef);
            IntPtr u      = CFLibrary.CFStringGetCharactersPtr(typeRef);
            IntPtr buffer = IntPtr.Zero;

            if (u == IntPtr.Zero)
            {
                CFRange range = new CFRange(0, length);
                buffer = Marshal.AllocCoTaskMem(length * 2);
                CFLibrary.CFStringGetCharacters(typeRef, range, buffer);
                u = buffer;
            }
            unsafe
            {
                str = new string((char *)u, 0, length);
            }
            if (buffer != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(buffer);
            }
            return(str);
        }
示例#4
0
        public override string ToString()
        {
            int ntype = CFLibrary.CFGetTypeID(typeRef);

            if (_CFString == ntype)
            {
                return(CFString());
            }
            else if (_CFDictionary == ntype)
            {
                return(CFDictionary());
            }
            else if (_CFArray == ntype)
            {
                return(CFPropertyList());
            }
            else if (_CFData == ntype)
            {
                return(CFData());
            }
            else if (_CFBoolean == ntype)
            {
                return(CFBoolean());
            }
            else if (_CFNumber == ntype)
            {
                return(CFNumber());
            }
            return(null);
        }
示例#5
0
        public void GetKeysAndValues(out IntPtr[] keys, out IntPtr[] values)
        {
            int count = this.Length;

            keys   = new IntPtr[count];
            values = new IntPtr[count];
            CFLibrary.CFDictionaryGetKeysAndValues(base.typeRef, keys, values);
        }
示例#6
0
        /// <summary>
        /// Retrieves a value at a given index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public CFType GetValue(int index)
        {
            if (index >= GetCount)
            {
                return(new CFType(IntPtr.Zero));
            }

            return(new CFType(CFLibrary.CFArrayGetValueAtIndex(typeRef, index)));
        }
示例#7
0
        unsafe public CFData(byte[] Data)
        {
            byte[] buffer = Data;
            int    len    = buffer.Length;

            fixed(byte *bytePtr = buffer)

            base.typeRef = CFLibrary.CFDataCreate(IntPtr.Zero, (IntPtr)bytePtr, len);
        }
示例#8
0
 /// <summary>
 /// Returns the value associated with a given key.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public CFType GetValue(string value)
 {
     try
     {
         return(new CFType(CFLibrary.CFDictionaryGetValue(base.typeRef, new CFString(value))));
     }
     catch (Exception)
     {
         return(new CFType(IntPtr.Zero));
     }
 }
示例#9
0
 public CFArray(IntPtr[] values)
 {
     try
     {
         typeRef = CFLibrary.CFArrayCreate(IntPtr.Zero, values, values.Length, IntPtr.Zero);
     }
     catch (Exception)
     {
         typeRef = IntPtr.Zero;
     }
 }
示例#10
0
        /// <summary>
        /// Returns the CFData object as a byte array
        /// </summary>
        /// <returns></returns>
        unsafe public byte[] ToByteArray()
        {
            int len = Length();

            byte[] buffer = new byte[len];

            fixed(byte *bufPtr = buffer)
            CFLibrary.CFDataGetBytes(typeRef, new CFRange(0, len), (IntPtr)bufPtr);

            return(buffer);
        }
示例#11
0
        unsafe public CFDictionary(string[] keys, IntPtr[] values)
        {
            IntPtr[] keyz = new IntPtr[keys.Length];
            for (int i = 0; i < keys.Length; i++)
            {
                keyz[i] = new CFString(keys[i]);
            }
            CFDictionaryKeyCallBacks kcall = new CFDictionaryKeyCallBacks();

            CFDictionaryValueCallBacks vcall = new CFDictionaryValueCallBacks();

            base.typeRef = CFLibrary.CFDictionaryCreate(IntPtr.Zero, keyz, values, keys.Length, ref kcall, ref vcall);
        }
示例#12
0
        private string CFString()
        {
            if (typeRef == IntPtr.Zero)
            {
                return(null);
            }
            int length = CFLibrary.CFStringGetLength(this);

            byte[] ch = new byte[length];
            for (int i = 0; i < length; i++)
            {
                ch[i] = CFLibrary.CFStringGetCharacterAtIndex(this, i);
            }
            return(Encoding.UTF8.GetString(ch));
        }
示例#13
0
        public CFPropertyList(string plistlocation)
        {
            IntPtr inputfilename;

            inputfilename = new CFString(plistlocation);

            IntPtr ifile_IntPtr          = CFLibrary.CFURLCreateWithFileSystemPath(IntPtr.Zero, inputfilename, 2, false);
            IntPtr ifile_CFReadStreamRef = CFLibrary.CFReadStreamCreateWithFile(IntPtr.Zero, ifile_IntPtr);

            if ((CFLibrary.CFReadStreamOpen(ifile_CFReadStreamRef)) == false)
            {
                typeRef = IntPtr.Zero;
            }
            IntPtr PlistRef = CFLibrary.CFPropertyListCreateFromStream(IntPtr.Zero, ifile_CFReadStreamRef, 0, 2, 0, IntPtr.Zero);

            CFLibrary.CFReadStreamClose(ifile_CFReadStreamRef);
            typeRef = PlistRef;
        }
示例#14
0
        private string CFDictionary()
        {
            StringBuilder sb   = new StringBuilder();
            string        sxml = CFPropertyList();

            sxml = sxml.Replace("\n", "");
            sb.AppendLine(sxml);
            int nCount = CFLibrary.CFDictionaryGetCount(typeRef);

            IntPtr[] keys   = new IntPtr[nCount];
            IntPtr[] values = new IntPtr[nCount];
            CFLibrary.CFDictionaryGetKeysAndValues(typeRef, keys, values);
            for (int i = 0; i < keys.Length; i++)
            {
                sb.AppendLine(new CFType(keys[i]).ToString() + "=" + new CFType(values[i]).ToString());
            }

            return(sb.ToString());
        }
示例#15
0
 /// <summary>
 /// Checks if the object is a valid CFData object
 /// </summary>
 /// <returns></returns>
 public bool isData()
 {
     return(CFLibrary.CFGetTypeID(typeRef) == _CFData);
 }
示例#16
0
 /// <summary>
 /// Returns the number of bytes contained by the CFData object
 /// </summary>
 /// <returns></returns>
 public int Length()
 {
     return(CFLibrary.CFDataGetLength(typeRef));
 }
示例#17
0
        unsafe public CFNumber(int Number)
        {
            int *pNumber = &Number;

            base.typeRef = CFLibrary.CFNumberCreate(IntPtr.Zero, CFNumberType.kCFNumberIntType, pNumber);
        }
示例#18
0
 /// <summary>
 /// Returns a textual description of a CoreFoundation object
 /// </summary>
 /// <returns></returns>
 public string GetDescription()
 {
     return(new CFString(CFLibrary.CFCopyDescription(typeRef)).ToString());
 }
示例#19
0
 /// <summary>
 /// Returns the unique identifier of an opaque type to which a CoreFoundation object belongs
 /// </summary>
 /// <returns></returns>
 public int GetTypeID()
 {
     return(CFLibrary.CFGetTypeID(typeRef));
 }
示例#20
0
 private string CFPropertyList()
 {
     return(Encoding.UTF8.GetString(new CFData(CFLibrary.CFPropertyListCreateXMLData(IntPtr.Zero, typeRef)).ToByteArray()));
 }
示例#21
0
 private string CFBoolean()
 {
     return(CFLibrary.CFBooleanGetValue(typeRef).ToString());
 }
示例#22
0
 /// <summary>
 /// Creates an immutable string from a constant compile-time string
 /// </summary>
 /// <param name="str"></param>
 unsafe public CFString(string str)
 {
     base.typeRef = CFLibrary.__CFStringMakeConstantString(str);
 }
示例#23
0
 /// <summary>
 /// Checks if the current object is a valid CFString object
 /// </summary>
 /// <returns></returns>
 public bool isString()
 {
     return(CFLibrary.CFGetTypeID(typeRef) == _CFString);
 }