/// <summary> /// Checks whether a given value is contained in this dictionary. /// </summary> /// <param name="val">The value that will be searched for.</param> /// <returns>Whether the key is contained in this dictionary.</returns> public bool ContainsValue(long val) { foreach (NSObject o in dict.Values) { if (o.GetType().Equals(typeof(NSNumber))) { NSNumber num = (NSNumber)o; if (num.isInteger() && num.ToInt() == val) { return(true); } } } return(false); }
/// <summary> /// Converts this NSObject into an equivalent object /// of the .NET Runtime Environment. /// <para><see cref="NSArray" /> objects are converted to arrays.</para> /// <para> /// <see cref="NSDictionary" /> objects are converted to objects extending the /// <see cref="Dictionary{TKey, TValue}" /> class. /// </para> /// <para><see cref="NSSet" /> objects are converted to objects extending the <see cref="List{NSObject}" /> class.</para> /// <para> /// <see cref="NSNumber" /> objects are converted to primitive number values (<see cref="int" />, /// <see cref="long" />, <see cref="double" /> or <see cref="bool" />). /// </para> /// <para><see cref="NSString" /> objects are converted to <see cref="string" /> objects.</para> /// <para><see cref="NSData" /> objects are converted to <see cref="byte" /> arrays.</para> /// <para><see cref="NSDate" /> objects are converted to <see cref="System.DateTime" /> objects.</para> /// <para><see cref="UID" /> objects are converted to <see cref="byte" /> arrays.</para> /// </summary> /// <returns>A native .NET object representing this NSObject's value.</returns> public object ToObject() { if (this is NSArray) { NSArray nsArray = (NSArray)this; object[] array = new object[nsArray.Count]; for (int i = 0; i < nsArray.Count; i++) { array[i] = nsArray[i].ToObject(); } return(array); } if (this is NSDictionary) { Dictionary <string, NSObject> dictA = ((NSDictionary)this).GetDictionary(); Dictionary <string, object> dictB = new Dictionary <string, object>(dictA.Count); foreach (KeyValuePair <string, NSObject> kvp in dictA) { dictB.Add(kvp.Key, kvp.Value.ToObject()); } return(dictB); } if (this is NSSet) { List <NSObject> setA = ((NSSet)this).GetSet(); List <object> setB = new List <object>(); foreach (NSObject o in setA) { setB.Add(o.ToObject()); } return(setB); } if (this is NSNumber) { NSNumber num = (NSNumber)this; switch (num.GetNSNumberType()) { case NSNumber.INTEGER: { long longVal = num.ToLong(); if (longVal > int.MaxValue || longVal < int.MinValue) { return(longVal); } return(num.ToInt()); } case NSNumber.REAL: return(num.ToDouble()); case NSNumber.BOOLEAN: return(num.ToBool()); default: return(num.ToDouble()); } } if (this is NSString) { return(((NSString)this).Content); } if (this is NSData) { return(((NSData)this).Bytes); } if (this is NSDate) { return(((NSDate)this).Date); } if (this is UID) { return(((UID)this).Bytes); } return(this); }
/// <summary> /// Converts this NSObject into an equivalent object /// of the .NET Runtime Environment. /// <para><see cref="NSArray"/> objects are converted to arrays.</para> /// <para><see cref="NSDictionary"/> objects are converted to objects extending the <see cref="Dictionary{TKey, TValue}"/> class.</para> /// <para><see cref="NSSet"/> objects are converted to objects extending the <see cref="List{NSObject}"/> class.</para> /// <para><see cref="NSNumber"/> objects are converted to primitive number values (<see cref="int"/>, <see cref="long"/>, <see cref="double"/> or <see cref="bool"/>).</para> /// <para><see cref="NSString"/> objects are converted to <see cref="string"/> objects.</para> /// <para><see cref="NSData"/> objects are converted to <see cref="byte"/> arrays.</para> /// <para><see cref="NSDate"/> objects are converted to <see cref="System.DateTime"/> objects.</para> /// <para><see cref="UID"/> objects are converted to <see cref="byte"/> arrays.</para> /// </summary> /// <returns>A native .NET object representing this NSObject's value.</returns> public Object ToObject() { if (this is NSArray) { NSObject[] arrayA = ((NSArray)this).GetArray(); Object[] arrayB = new Object[arrayA.Length]; for (int i = 0; i < arrayA.Length; i++) { arrayB[i] = arrayA[i].ToObject(); } return(arrayB); } if (this is NSDictionary) { Dictionary <string, NSObject> dictA = ((NSDictionary)this).GetDictionary(); Dictionary <string, Object> dictB = new Dictionary <string, Object>(dictA.Count); foreach (KeyValuePair <string, NSObject> kvp in dictA) { dictB.Add(kvp.Key, kvp.Value.ToObject()); } return(dictB); } if (this is NSSet) { List <NSObject> setA = ((NSSet)this).GetSet(); List <Object> setB = new List <Object>(); foreach (NSObject o in setA) { setB.Add(o.ToObject()); } return(setB); } if (this is NSNumber) { NSNumber num = (NSNumber)this; switch (num.Type) { case NumberType.Integer: { long longVal = num.ToLong(); if (longVal > int.MaxValue || longVal < int.MinValue) { return(longVal); } return(num.ToInt()); } case NumberType.Real: return(num.ToDouble()); case NumberType.Boolean: return(num.ToBool()); default: return(num.ToDouble()); } } if (this is NSString) { return(((NSString)this).Content); } if (this is NSData) { return(((NSData)this).Bytes); } if (this is NSDate) { return(((NSDate)this).Date); } if (this is UID) { return(((UID)this).Bytes); } return(this); }