GetFieldID() public static method

public static GetFieldID ( IntPtr javaClass, string fieldName ) : IntPtr
javaClass IntPtr
fieldName string
return IntPtr
        public static IntPtr GetFieldID(IntPtr javaClass, string fieldName)
        {
            bool   isStatic  = false;
            string signature = "";

            return(AndroidJNIHelper.GetFieldID(javaClass, fieldName, signature, isStatic));
        }
Esempio n. 2
0
        public static IntPtr GetFieldID(IntPtr javaClass, string fieldName)
        {
            bool   isStatic = false;
            string empty    = string.Empty;

            return(AndroidJNIHelper.GetFieldID(javaClass, fieldName, empty, isStatic));
        }
Esempio n. 3
0
        protected FieldType _GetStatic <FieldType>(string fieldName)
        {
            IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true);

            if (AndroidReflection.IsPrimitive(typeof(FieldType)))
            {
                if (typeof(FieldType) == typeof(int))
                {
                    return((FieldType)AndroidJNISafe.GetStaticIntField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(bool))
                {
                    return((FieldType)AndroidJNISafe.GetStaticBooleanField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(byte))
                {
                    return((FieldType)AndroidJNISafe.GetStaticByteField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(short))
                {
                    return((FieldType)AndroidJNISafe.GetStaticShortField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(long))
                {
                    return((FieldType)AndroidJNISafe.GetStaticLongField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(float))
                {
                    return((FieldType)AndroidJNISafe.GetStaticFloatField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(double))
                {
                    return((FieldType)AndroidJNISafe.GetStaticDoubleField(this.m_jclass, fieldID));
                }
                if (typeof(FieldType) == typeof(char))
                {
                    return((FieldType)AndroidJNISafe.GetStaticCharField(this.m_jclass, fieldID));
                }
                return(default(FieldType));
            }
            if (typeof(FieldType) == typeof(string))
            {
                return((FieldType)AndroidJNISafe.GetStaticStringField(this.m_jclass, fieldID));
            }
            if (typeof(FieldType) == typeof(AndroidJavaClass))
            {
                return((FieldType)AndroidJavaClassDeleteLocalRef(AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID)));
            }
            if (typeof(FieldType) == typeof(AndroidJavaObject))
            {
                return((FieldType)AndroidJavaObjectDeleteLocalRef(AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID)));
            }
            if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)))
            {
                throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'");
            }
            return(AndroidJNIHelper.ConvertFromJNIArray <FieldType>(AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID)));
        }
Esempio n. 4
0
        protected FieldType _Get <FieldType>(string fieldName)
        {
            IntPtr fieldId = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, false);

            if (AndroidReflection.IsPrimitive(typeof(FieldType)))
            {
                if (typeof(FieldType) == typeof(int))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetIntField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(bool))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetBooleanField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(byte))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetByteField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(short))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetShortField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(long))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetLongField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(float))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetFloatField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(double))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetDoubleField(this.m_jobject, fieldId));
                }
                if (typeof(FieldType) == typeof(char))
                {
                    return((FieldType)(ValueType)AndroidJNISafe.GetCharField(this.m_jobject, fieldId));
                }
                return(default(FieldType));
            }
            if (typeof(FieldType) == typeof(string))
            {
                return((FieldType)AndroidJNISafe.GetStringField(this.m_jobject, fieldId));
            }
            if (typeof(FieldType) == typeof(AndroidJavaClass))
            {
                return((FieldType)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(AndroidJNISafe.GetObjectField(this.m_jobject, fieldId)));
            }
            if (typeof(FieldType) == typeof(AndroidJavaObject))
            {
                return((FieldType)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNISafe.GetObjectField(this.m_jobject, fieldId)));
            }
            if (AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)))
            {
                return(AndroidJNIHelper.ConvertFromJNIArray <FieldType>(AndroidJNISafe.GetObjectField(this.m_jobject, fieldId)));
            }
            throw new Exception("JNI: Unknown field type '" + (object)typeof(FieldType) + "'");
        }
Esempio n. 5
0
        protected void _SetStatic <FieldType>(string fieldName, FieldType val)
        {
            IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true);

            if (AndroidReflection.IsPrimitive(typeof(FieldType)))
            {
                if (typeof(FieldType) == typeof(int))
                {
                    AndroidJNISafe.SetStaticIntField(this.m_jclass, fieldID, (int)val);
                }
                else if (typeof(FieldType) == typeof(bool))
                {
                    AndroidJNISafe.SetStaticBooleanField(this.m_jclass, fieldID, (bool)val);
                }
                else if (typeof(FieldType) == typeof(byte))
                {
                    AndroidJNISafe.SetStaticByteField(this.m_jclass, fieldID, (byte)val);
                }
                else if (typeof(FieldType) == typeof(short))
                {
                    AndroidJNISafe.SetStaticShortField(this.m_jclass, fieldID, (short)val);
                }
                else if (typeof(FieldType) == typeof(long))
                {
                    AndroidJNISafe.SetStaticLongField(this.m_jclass, fieldID, (long)val);
                }
                else if (typeof(FieldType) == typeof(float))
                {
                    AndroidJNISafe.SetStaticFloatField(this.m_jclass, fieldID, (float)val);
                }
                else if (typeof(FieldType) == typeof(double))
                {
                    AndroidJNISafe.SetStaticDoubleField(this.m_jclass, fieldID, (double)val);
                }
                else if (typeof(FieldType) == typeof(char))
                {
                    AndroidJNISafe.SetStaticCharField(this.m_jclass, fieldID, (char)val);
                }
            }
            else if (typeof(FieldType) == typeof(string))
            {
                AndroidJNISafe.SetStaticStringField(this.m_jclass, fieldID, (string)val);
            }
            else if (typeof(FieldType) == typeof(AndroidJavaClass))
            {
                AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, ((AndroidJavaClass)val).m_jclass);
            }
            else if (typeof(FieldType) == typeof(AndroidJavaObject))
            {
                AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, ((AndroidJavaObject)val).m_jobject);
            }
            else
            {
                if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)))
                {
                    throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'");
                }
                IntPtr ptr2 = AndroidJNIHelper.ConvertToJNIArray((Array)val);
                AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, ptr2);
            }
        }
Esempio n. 6
0
 public static IntPtr GetFieldID <ReturnType>(IntPtr jclass, string fieldName, bool isStatic)
 {
     return(AndroidJNIHelper.GetFieldID(jclass, fieldName, GetSignature(typeof(ReturnType)), isStatic));
 }
Esempio n. 7
0
        protected void _Set <FieldType>(string fieldName, FieldType val)
        {
            IntPtr fieldId = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, false);

            if (AndroidReflection.IsPrimitive(typeof(FieldType)))
            {
                if (typeof(FieldType) == typeof(int))
                {
                    AndroidJNISafe.SetIntField(this.m_jobject, fieldId, (int)(object)val);
                }
                else if (typeof(FieldType) == typeof(bool))
                {
                    AndroidJNISafe.SetBooleanField(this.m_jobject, fieldId, (bool)(object)val);
                }
                else if (typeof(FieldType) == typeof(byte))
                {
                    AndroidJNISafe.SetByteField(this.m_jobject, fieldId, (byte)(object)val);
                }
                else if (typeof(FieldType) == typeof(short))
                {
                    AndroidJNISafe.SetShortField(this.m_jobject, fieldId, (short)(object)val);
                }
                else if (typeof(FieldType) == typeof(long))
                {
                    AndroidJNISafe.SetLongField(this.m_jobject, fieldId, (long)(object)val);
                }
                else if (typeof(FieldType) == typeof(float))
                {
                    AndroidJNISafe.SetFloatField(this.m_jobject, fieldId, (float)(object)val);
                }
                else if (typeof(FieldType) == typeof(double))
                {
                    AndroidJNISafe.SetDoubleField(this.m_jobject, fieldId, (double)(object)val);
                }
                else
                {
                    if (typeof(FieldType) != typeof(char))
                    {
                        return;
                    }
                    AndroidJNISafe.SetCharField(this.m_jobject, fieldId, (char)(object)val);
                }
            }
            else if (typeof(FieldType) == typeof(string))
            {
                AndroidJNISafe.SetStringField(this.m_jobject, fieldId, (string)(object)val);
            }
            else if (typeof(FieldType) == typeof(AndroidJavaClass))
            {
                AndroidJNISafe.SetObjectField(this.m_jobject, fieldId, ((AndroidJavaObject)(object)val).m_jclass);
            }
            else if (typeof(FieldType) == typeof(AndroidJavaObject))
            {
                AndroidJNISafe.SetObjectField(this.m_jobject, fieldId, ((AndroidJavaObject)(object)val).m_jobject);
            }
            else
            {
                if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)))
                {
                    throw new Exception("JNI: Unknown field type '" + (object)typeof(FieldType) + "'");
                }
                IntPtr jniArray = AndroidJNIHelper.ConvertToJNIArray((Array)(object)val);
                AndroidJNISafe.SetObjectField(this.m_jclass, fieldId, jniArray);
            }
        }
 public static IntPtr GetFieldID(IntPtr javaClass, string fieldName, [DefaultValue("")] string signature)
 {
     return(AndroidJNIHelper.GetFieldID(javaClass, fieldName, signature, false));
 }
 public static IntPtr GetFieldID(IntPtr javaClass, string fieldName)
 {
     return(AndroidJNIHelper.GetFieldID(javaClass, fieldName, "", false));
 }
        protected FieldType _Get <FieldType>(string fieldName)
        {
            IntPtr    fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, false);
            FieldType result;

            if (AndroidReflection.IsPrimitive(typeof(FieldType)))
            {
                if (typeof(FieldType) == typeof(int))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetIntField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(bool))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetBooleanField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(byte))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetByteField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(short))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetShortField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(long))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetLongField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(float))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetFloatField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(double))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetDoubleField(this.m_jobject, fieldID));
                }
                else if (typeof(FieldType) == typeof(char))
                {
                    result = (FieldType)((object)AndroidJNISafe.GetCharField(this.m_jobject, fieldID));
                }
                else
                {
                    result = default(FieldType);
                }
            }
            else if (typeof(FieldType) == typeof(string))
            {
                result = (FieldType)((object)AndroidJNISafe.GetStringField(this.m_jobject, fieldID));
            }
            else if (typeof(FieldType) == typeof(AndroidJavaClass))
            {
                IntPtr objectField = AndroidJNISafe.GetObjectField(this.m_jobject, fieldID);
                result = ((!(objectField == IntPtr.Zero)) ? ((FieldType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(objectField))) : default(FieldType));
            }
            else if (typeof(FieldType) == typeof(AndroidJavaObject))
            {
                IntPtr objectField2 = AndroidJNISafe.GetObjectField(this.m_jobject, fieldID);
                result = ((!(objectField2 == IntPtr.Zero)) ? ((FieldType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(objectField2))) : default(FieldType));
            }
            else
            {
                if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)))
                {
                    throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'");
                }
                IntPtr objectField3 = AndroidJNISafe.GetObjectField(this.m_jobject, fieldID);
                result = ((!(objectField3 == IntPtr.Zero)) ? ((FieldType)((object)AndroidJNIHelper.ConvertFromJNIArray <FieldType>(objectField3))) : default(FieldType));
            }
            return(result);
        }
Esempio n. 11
0
        protected void _SetStatic <FieldType>(string fieldName, FieldType val)
        {
            IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true);
            bool   flag    = AndroidReflection.IsPrimitive(typeof(FieldType));

            if (flag)
            {
                bool flag2 = typeof(FieldType) == typeof(int);
                if (flag2)
                {
                    AndroidJNISafe.SetStaticIntField(this.m_jclass, fieldID, (int)((object)val));
                }
                else
                {
                    bool flag3 = typeof(FieldType) == typeof(bool);
                    if (flag3)
                    {
                        AndroidJNISafe.SetStaticBooleanField(this.m_jclass, fieldID, (bool)((object)val));
                    }
                    else
                    {
                        bool flag4 = typeof(FieldType) == typeof(byte);
                        if (flag4)
                        {
                            Debug.LogWarning("Field type <Byte> for Java set field call is obsolete, use field type <SByte> instead");
                            AndroidJNISafe.SetStaticSByteField(this.m_jclass, fieldID, (sbyte)((byte)((object)val)));
                        }
                        else
                        {
                            bool flag5 = typeof(FieldType) == typeof(sbyte);
                            if (flag5)
                            {
                                AndroidJNISafe.SetStaticSByteField(this.m_jclass, fieldID, (sbyte)((object)val));
                            }
                            else
                            {
                                bool flag6 = typeof(FieldType) == typeof(short);
                                if (flag6)
                                {
                                    AndroidJNISafe.SetStaticShortField(this.m_jclass, fieldID, (short)((object)val));
                                }
                                else
                                {
                                    bool flag7 = typeof(FieldType) == typeof(long);
                                    if (flag7)
                                    {
                                        AndroidJNISafe.SetStaticLongField(this.m_jclass, fieldID, (long)((object)val));
                                    }
                                    else
                                    {
                                        bool flag8 = typeof(FieldType) == typeof(float);
                                        if (flag8)
                                        {
                                            AndroidJNISafe.SetStaticFloatField(this.m_jclass, fieldID, (float)((object)val));
                                        }
                                        else
                                        {
                                            bool flag9 = typeof(FieldType) == typeof(double);
                                            if (flag9)
                                            {
                                                AndroidJNISafe.SetStaticDoubleField(this.m_jclass, fieldID, (double)((object)val));
                                            }
                                            else
                                            {
                                                bool flag10 = typeof(FieldType) == typeof(char);
                                                if (flag10)
                                                {
                                                    AndroidJNISafe.SetStaticCharField(this.m_jclass, fieldID, (char)((object)val));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                bool flag11 = typeof(FieldType) == typeof(string);
                if (flag11)
                {
                    AndroidJNISafe.SetStaticStringField(this.m_jclass, fieldID, (string)((object)val));
                }
                else
                {
                    bool flag12 = typeof(FieldType) == typeof(AndroidJavaClass);
                    if (flag12)
                    {
                        AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, (val == null) ? IntPtr.Zero : ((AndroidJavaClass)((object)val)).m_jclass);
                    }
                    else
                    {
                        bool flag13 = typeof(FieldType) == typeof(AndroidJavaObject);
                        if (flag13)
                        {
                            AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, (val == null) ? IntPtr.Zero : ((AndroidJavaObject)((object)val)).m_jobject);
                        }
                        else
                        {
                            bool flag14 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType));
                            if (!flag14)
                            {
                                string arg_3B5_0 = "JNI: Unknown field type '";
                                Type   expr_3A4  = typeof(FieldType);
                                throw new Exception(arg_3B5_0 + ((expr_3A4 != null) ? expr_3A4.ToString() : null) + "'");
                            }
                            IntPtr val2 = AndroidJNIHelper.ConvertToJNIArray((Array)((object)val));
                            AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, val2);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        protected FieldType _GetStatic <FieldType>(string fieldName)
        {
            IntPtr    fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true);
            bool      flag    = AndroidReflection.IsPrimitive(typeof(FieldType));
            FieldType result;

            if (flag)
            {
                bool flag2 = typeof(FieldType) == typeof(int);
                if (flag2)
                {
                    result = (FieldType)((object)AndroidJNISafe.GetStaticIntField(this.m_jclass, fieldID));
                }
                else
                {
                    bool flag3 = typeof(FieldType) == typeof(bool);
                    if (flag3)
                    {
                        result = (FieldType)((object)AndroidJNISafe.GetStaticBooleanField(this.m_jclass, fieldID));
                    }
                    else
                    {
                        bool flag4 = typeof(FieldType) == typeof(byte);
                        if (flag4)
                        {
                            Debug.LogWarning("Field type <Byte> for Java get field call is obsolete, use field type <SByte> instead");
                            result = (FieldType)((object)((byte)AndroidJNISafe.GetStaticSByteField(this.m_jclass, fieldID)));
                        }
                        else
                        {
                            bool flag5 = typeof(FieldType) == typeof(sbyte);
                            if (flag5)
                            {
                                result = (FieldType)((object)AndroidJNISafe.GetStaticSByteField(this.m_jclass, fieldID));
                            }
                            else
                            {
                                bool flag6 = typeof(FieldType) == typeof(short);
                                if (flag6)
                                {
                                    result = (FieldType)((object)AndroidJNISafe.GetStaticShortField(this.m_jclass, fieldID));
                                }
                                else
                                {
                                    bool flag7 = typeof(FieldType) == typeof(long);
                                    if (flag7)
                                    {
                                        result = (FieldType)((object)AndroidJNISafe.GetStaticLongField(this.m_jclass, fieldID));
                                    }
                                    else
                                    {
                                        bool flag8 = typeof(FieldType) == typeof(float);
                                        if (flag8)
                                        {
                                            result = (FieldType)((object)AndroidJNISafe.GetStaticFloatField(this.m_jclass, fieldID));
                                        }
                                        else
                                        {
                                            bool flag9 = typeof(FieldType) == typeof(double);
                                            if (flag9)
                                            {
                                                result = (FieldType)((object)AndroidJNISafe.GetStaticDoubleField(this.m_jclass, fieldID));
                                            }
                                            else
                                            {
                                                bool flag10 = typeof(FieldType) == typeof(char);
                                                if (flag10)
                                                {
                                                    result = (FieldType)((object)AndroidJNISafe.GetStaticCharField(this.m_jclass, fieldID));
                                                }
                                                else
                                                {
                                                    result = default(FieldType);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                bool flag11 = typeof(FieldType) == typeof(string);
                if (flag11)
                {
                    result = (FieldType)((object)AndroidJNISafe.GetStaticStringField(this.m_jclass, fieldID));
                }
                else
                {
                    bool flag12 = typeof(FieldType) == typeof(AndroidJavaClass);
                    if (flag12)
                    {
                        IntPtr staticObjectField = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID);
                        result = ((staticObjectField == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(staticObjectField))));
                    }
                    else
                    {
                        bool flag13 = typeof(FieldType) == typeof(AndroidJavaObject);
                        if (flag13)
                        {
                            IntPtr staticObjectField2 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID);
                            result = ((staticObjectField2 == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(staticObjectField2))));
                        }
                        else
                        {
                            bool flag14 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType));
                            if (!flag14)
                            {
                                string arg_3D3_0 = "JNI: Unknown field type '";
                                Type   expr_3C2  = typeof(FieldType);
                                throw new Exception(arg_3D3_0 + ((expr_3C2 != null) ? expr_3C2.ToString() : null) + "'");
                            }
                            IntPtr staticObjectField3 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID);
                            result = ((staticObjectField3 == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJNIHelper.ConvertFromJNIArray <FieldType>(staticObjectField3))));
                        }
                    }
                }
            }
            return(result);
        }