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!"); } }
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); }
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); }
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); }
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); }
/// <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))); }
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); }
/// <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)); } }
public CFArray(IntPtr[] values) { try { typeRef = CFLibrary.CFArrayCreate(IntPtr.Zero, values, values.Length, IntPtr.Zero); } catch (Exception) { typeRef = IntPtr.Zero; } }
/// <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); }
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); }
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)); }
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; }
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()); }
/// <summary> /// Checks if the object is a valid CFData object /// </summary> /// <returns></returns> public bool isData() { return(CFLibrary.CFGetTypeID(typeRef) == _CFData); }
/// <summary> /// Returns the number of bytes contained by the CFData object /// </summary> /// <returns></returns> public int Length() { return(CFLibrary.CFDataGetLength(typeRef)); }
unsafe public CFNumber(int Number) { int *pNumber = &Number; base.typeRef = CFLibrary.CFNumberCreate(IntPtr.Zero, CFNumberType.kCFNumberIntType, pNumber); }
/// <summary> /// Returns a textual description of a CoreFoundation object /// </summary> /// <returns></returns> public string GetDescription() { return(new CFString(CFLibrary.CFCopyDescription(typeRef)).ToString()); }
/// <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)); }
private string CFPropertyList() { return(Encoding.UTF8.GetString(new CFData(CFLibrary.CFPropertyListCreateXMLData(IntPtr.Zero, typeRef)).ToByteArray())); }
private string CFBoolean() { return(CFLibrary.CFBooleanGetValue(typeRef).ToString()); }
/// <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); }
/// <summary> /// Checks if the current object is a valid CFString object /// </summary> /// <returns></returns> public bool isString() { return(CFLibrary.CFGetTypeID(typeRef) == _CFString); }