Пример #1
0
        //
        // Exception audit:
        //
        //  Verdict
        //    No need to wrap thrown exceptions in a BCL class
        //
        //  Rationale
        //    `java.util.Collection.toArray()` is not documented to throw any exceptions.
        //
        public void CopyTo(Array array, int array_index)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (array_index < 0)
            {
                throw new ArgumentOutOfRangeException("array_index");
            }
            if (array.Length < array_index + Count)
            {
                throw new ArgumentException("array");
            }

            if (id_toArray == IntPtr.Zero)
            {
                id_toArray = JNIEnv.GetMethodID(collection_class, "toArray", "()[Ljava/lang/Object;");
            }

            IntPtr lrefArray = JNIEnv.CallObjectMethod(Handle, id_toArray);

            for (int i = 0; i < Count; i++)
            {
                array.SetValue(
                    JavaConvert.FromJniHandle(
                        JNIEnv.GetObjectArrayElement(lrefArray, i),
                        JniHandleOwnership.TransferLocalRef,
                        array.GetType().GetElementType()),
                    array_index + i);
            }
            JNIEnv.DeleteLocalRef(lrefArray);
        }
Пример #2
0
 public virtual E Get(int key)
 {
     if (id_get_I == IntPtr.Zero)
     {
         id_get_I = JNIEnv.GetMethodID(class_ref, "get", "(I)Ljava/lang/Object;");
     }
     return(JavaConvert.FromJniHandle <E>(JNIEnv.CallNonvirtualObjectMethod(Handle, class_ref, id_get_I, new JValue(key)), JniHandleOwnership.TransferLocalRef) !);
 }
Пример #3
0
 public TResult GetResult()
 {
     if (id_get == IntPtr.Zero)
     {
         id_get = JNIEnv.GetMethodID(class_ref, "get", "()Ljava/lang/Object;");
     }
     return(JavaConvert.FromJniHandle <TResult>(JNIEnv.CallObjectMethod(Handle, id_get), JniHandleOwnership.TransferLocalRef));
 }
Пример #4
0
 internal static IEnumerator <T> ToEnumerator_Dispose <T> (this Java.Util.IIterator source)
 {
     using (source)
         while (source.HasNext)
         {
             yield return(JavaConvert.FromJniHandle <T>(
                              JNIEnv.CallObjectMethod(source.Handle, id_next),
                              JniHandleOwnership.TransferLocalRef));
         }
 }
Пример #5
0
 public T GetItem(int position)
 {
     if (id_getItem_I == IntPtr.Zero)
     {
         id_getItem_I = JNIEnv.GetMethodID(class_ref, "getItem", "(I)Ljava/lang/Object;");
     }
     return(JavaConvert.FromJniHandle <T>(
                JNIEnv.CallNonvirtualObjectMethod(Handle, class_ref, id_getItem_I, new JValue(position)),
                JniHandleOwnership.TransferLocalRef));
 }
Пример #6
0
 public static Android.Widget.ArrayAdapter <Java.Lang.ICharSequence> CreateFromResource(Android.Content.Context context, int textArrayResId, int textViewResId)
 {
     if (id_createFromResource_Landroid_content_Context_II == IntPtr.Zero)
     {
         id_createFromResource_Landroid_content_Context_II = JNIEnv.GetStaticMethodID(class_ref, "createFromResource", "(Landroid/content/Context;II)Landroid/widget/ArrayAdapter;");
     }
     return(JavaConvert.FromJniHandle <ArrayAdapter <Java.Lang.ICharSequence> > (
                JNIEnv.CallStaticObjectMethod(class_ref, id_createFromResource_Landroid_content_Context_II, new JValue(context), new JValue(textArrayResId), new JValue(textViewResId)),
                JniHandleOwnership.TransferLocalRef) !);
 }
Пример #7
0
        public virtual E Get(int key, E valueIfKeyNotFound)
        {
            if (id_get_ILjava_lang_Object_ == IntPtr.Zero)
            {
                id_get_ILjava_lang_Object_ = JNIEnv.GetMethodID(class_ref, "get", "(ILjava/lang/Object;)Ljava/lang/Object;");
            }
            IntPtr value = JavaConvert.WithLocalJniHandle(valueIfKeyNotFound,
                                                          lref => JNIEnv.CallNonvirtualObjectMethod(Handle, class_ref, id_get_ILjava_lang_Object_, new JValue(key), new JValue(lref)));

            return(JavaConvert.FromJniHandle <E> (value, JniHandleOwnership.TransferLocalRef) !);
        }
Пример #8
0
 internal object InternalGet(int location, Type targetType = null)
 {
     if (id_get == IntPtr.Zero)
     {
         id_get = JNIEnv.GetMethodID(arraylist_class, "get", "(I)Ljava/lang/Object;");
     }
     return(JavaConvert.FromJniHandle(
                JNIEnv.CallObjectMethod(Handle, id_get, new JValue(location)),
                JniHandleOwnership.TransferLocalRef,
                targetType));
 }
Пример #9
0
 internal object Get(object key)
 {
     if (id_get == IntPtr.Zero)
     {
         id_get = JNIEnv.GetMethodID(map_class, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
     }
     return(JavaConvert.FromJniHandle(
                JavaConvert.WithLocalJniHandle(key,
                                               lref => JNIEnv.CallObjectMethod(Handle, id_get, new JValue(lref))),
                JniHandleOwnership.TransferLocalRef));
 }
Пример #10
0
 public static IEnumerable <T> ToEnumerable <T> (this Java.Lang.IIterable source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     using (var iterator = source.Iterator())
         while (iterator.HasNext)
         {
             yield return(JavaConvert.FromJniHandle <T>(
                              JNIEnv.CallObjectMethod(iterator.Handle, id_next),
                              JniHandleOwnership.TransferLocalRef));
         }
 }
Пример #11
0
		//
		// Exception audit:
		//
		//  Verdict
		//    Exception wrapping is required.
		//
		//  Rationale
		//    `java.util.Collection.get(Object, Object)` throws a number of exceptions, see:
		//
		//     https://developer.android.com/reference/java/util/Map#get(java.lang.Object)
		//
		internal object Get (object key)
		{
			if (id_get == IntPtr.Zero)
				id_get = JNIEnv.GetMethodID (map_class, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
			return JavaConvert.FromJniHandle (
				JavaConvert.WithLocalJniHandle (key, lref => {
					try {
						return JNIEnv.CallObjectMethod (Handle, id_get, new JValue (lref));
					} catch (Java.Lang.ClassCastException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
						throw new InvalidCastException (ex.Message, ex);
					} catch (Java.Lang.NullPointerException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
						throw new NullReferenceException (ex.Message, ex);
					}
				}), JniHandleOwnership.TransferLocalRef);
		}
Пример #12
0
        //
        // Exception audit:
        //
        //  Verdict
        //    Exception wrapping is required.
        //
        //  Rationale
        //    `java.util.List.get(int)` throws an exceptions, see:
        //
        //     https://developer.android.com/reference/java/util/List.html?hl=en#get(int)
        //
        internal object InternalGet(int location, Type targetType = null)
        {
            if (id_get == IntPtr.Zero)
            {
                id_get = JNIEnv.GetMethodID(arraylist_class, "get", "(I)Ljava/lang/Object;");
            }

            IntPtr obj;

            try {
                obj = JNIEnv.CallObjectMethod(Handle, id_get, new JValue(location));
            } catch (Java.Lang.IndexOutOfBoundsException ex) when(JNIEnv.ShouldWrapJavaException(ex))
            {
                throw new ArgumentOutOfRangeException(ex.Message, ex);
            }

            return(JavaConvert.FromJniHandle(
                       obj,
                       JniHandleOwnership.TransferLocalRef,
                       targetType));
        }