/// <summary> /// Gets the value of an object field. /// /// <para> /// NOTE: be sure you passing correct type (it shoud be the primitive or the type derived from <see cref="JavaObject"/>)! /// </para> /// /// </summary> /// <returns>The static object field.</returns> /// <param name="name">Field name.</param> /// <typeparam name="TFieldType"></typeparam> public TFieldType Get <TFieldType>(string name) { IntPtr fieldId = AndroidJNIHelper.GetFieldID(mClass, name, GetSignature <TFieldType>(), false); var t = typeof(TFieldType); if (AndroidReflection.IsPrimitive(t)) { if (typeof(TFieldType) == typeof(int)) { return((TFieldType)(object)JNISafe.GetIntField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(bool)) { return((TFieldType)(object)JNISafe.GetBooleanField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(byte)) { return((TFieldType)(object)JNISafe.GetByteField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(short)) { return((TFieldType)(object)JNISafe.GetShortField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(long)) { return((TFieldType)(object)JNISafe.GetLongField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(float)) { return((TFieldType)(object)JNISafe.GetFloatField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(double)) { return((TFieldType)(object)JNISafe.GetDoubleField(mObject, fieldId)); } if (typeof(TFieldType) == typeof(char)) { return((TFieldType)(object)JNISafe.GetCharField(mObject, fieldId)); } return(default(TFieldType)); } if (t == typeof(string)) { return((TFieldType)(object)JNISafe.GetStringField(mObject, fieldId)); } if (t.IsSubclassOf(typeof(JavaObject))) { IntPtr val = JNISafe.GetObjectField(mObject, fieldId); if (val == IntPtr.Zero) { return(default(TFieldType)); } ConstructorInfo c = t.GetConstructor(new[] { val.GetType() }); if (c != null) { return((TFieldType)c.Invoke(new object[] { val })); } DebugPrint("Can't instantiate class, probably no constructor with IntPtr arg"); } return(default(TFieldType)); }