protected void SetNativeValue(NSString key, INativeObject value, bool removeNullValue = true) { if (NullCheckAndRemoveKey(key, removeNullValue && value == null)) { CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, value == null ? IntPtr.Zero : value.Handle); } }
protected void SetArrayValue(NSString key, INativeObject[] values) { if (NullCheckAndRemoveKey(key, values == null)) { CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, CFArray.FromNativeObjects(values).Handle); } }
protected void SetBooleanValue(NSString key, bool?value) { if (NullCheckAndRemoveKey(key, !value.HasValue)) { CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, value.Value ? CFBoolean.TrueHandle : CFBoolean.FalseHandle); } }
public SecRecord(SecKind secKind) { var kind = SecClass.FromSecKind(secKind); _queryDict = CFMutableDictionary.Create(); _queryDict.SetValue(SecClassKey, kind); }
protected virtual void Dispose(bool disposing) { if (_queryDict != null) { if (disposing) { _queryDict.Dispose(); _queryDict = null; } } }
// 'Value must be a CFArray of CFNumberRefs' - System/Library/Frameworks/CoreText.framework/Headers/CTStringAttributes.h public void SetWritingDirection(params CTWritingDirection[] writingDirections) { var ptrs = new IntPtr [writingDirections.Length]; for (int i = 0; i < writingDirections.Length; ++i) { ptrs[i] = (new NSNumber((int)writingDirections[i])).Handle; } var array = CFArray.Create(ptrs); CFMutableDictionary.SetValue(Dictionary.Handle, CTStringAttributeKey.WritingDirection.Handle, array); }
public static void SetNativeValue(NSDictionary dictionary, NSObject key, INativeObject value) { if (value != null) { AssertWritable(dictionary); CFMutableDictionary.SetValue(dictionary.Handle, key.Handle, value.Handle); } else { IDictionary <NSObject, NSObject> d = dictionary; d.Remove(key); } }
protected void SetBooleanValue(NSString key, bool?value) { if (key == null) { throw new ArgumentNullException("key"); } if (value == null) { RemoveValue(key); return; } CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, value.Value ? CFBoolean.True.Handle : CFBoolean.False.Handle); }
protected void SetArrayValue(NSString key, INativeObject[] values) { if (key == null) { throw new ArgumentNullException("key"); } if (values == null) { RemoveValue(key); return; } CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, CFArray.FromNativeObjects(values).Handle); }
protected void SetNativeValue(NSString key, INativeObject value, bool removeNullValue = true) { if (key == null) { throw new ArgumentNullException("key"); } if (value == null && removeNullValue) { RemoveValue(key); } else { CFMutableDictionary.SetValue(Dictionary.Handle, key.Handle, value == null ? IntPtr.Zero : value.Handle); } }
// 'Value must be a CFArray of CFNumberRefs' - System/Library/Frameworks/CoreText.framework/Headers/CTStringAttributes.h public void SetWritingDirection(params CTWritingDirection[] writingDirections) { var ptrs = new NativeHandle [writingDirections.Length]; var numbers = new NSNumber [writingDirections.Length]; for (int i = 0; i < writingDirections.Length; ++i) { numbers [i] = new NSNumber((int)writingDirections [i]); ptrs [i] = numbers [i].Handle; } var array = CFArray.Create(ptrs); CFMutableDictionary.SetValue(Dictionary.Handle, CTStringAttributeKey.WritingDirection.Handle, array); GC.KeepAlive(numbers); // make sure the numbers aren't freed until we're done with them }
static SafeSecIdentityHandle FindIdentity(Predicate <SafeSecCertificateHandle> filter) { Initialize(); /* * Unfortunately, SecItemCopyMatching() does not allow any search * filters when looking up an identity. * * The following lookup will return all identities from the keychain - * we then need need to find the right one. */ using (var query = CFMutableDictionary.Create()) { query.SetValue(SecClassKey, SecClassIdentity); query.SetValue(CFBoolean.True.Handle, ReturnRef); query.SetValue(MatchLimitAll, MatchLimit); var status = SecItemCopyMatching(query.Handle, out var ptr); if (status != SecStatusCode.Success || ptr == IntPtr.Zero) { return(null); } using (var array = new CFArray(ptr, false)) { for (int i = 0; i < array.Count; i++) { var item = array[i]; if (!MonoCertificatePal.IsSecIdentity(item)) { throw new InvalidOperationException(); } using (var identity = new SafeSecIdentityHandle(item)) using (var certificate = MonoCertificatePal.GetCertificate(identity)) { if (filter(certificate)) { return(new SafeSecIdentityHandle(item)); } } } } } return(null); }
static CFNumber SetLimit(CFMutableDictionary dict, int max) { CFNumber n = null; IntPtr val; if (max == -1) { val = MatchLimitAll; } else if (max == 1) { val = MatchLimitOne; } else { n = CFNumber.FromInt32(max); val = n.Handle; } dict.SetValue(val, SecKeyChain.MatchLimit); return(n); }