Example #1
0
        public static bool TryGetMarshalMethod(this MethodDefinition method, string nativeMethod, string signature, out MethodDefinition marshalMethod)
        {
            marshalMethod = null;
            var type = method.DeclaringType;

            if (!type.HasNestedTypes)
            {
                return(false);
            }

            TypeDefinition marshalType = type.GetMarshalMethodsType();

            if (marshalType == null || !marshalType.HasMethods)
            {
                return(false);
            }

            var marshalMethodName = MarshalMemberBuilder.GetMarshalMethodName(nativeMethod, signature);

            if (marshalMethodName == null)
            {
                return(false);
            }

            foreach (var m in marshalType.Methods)
            {
                if (m.Name == marshalMethodName)
                {
                    marshalMethod = m;
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        static bool CheckMethod(MethodDefinition m, ref string name, ref string methodName, ref string signature)
        {
            foreach (var registerAttribute in m.GetCustomAttributes("Android.Runtime.RegisterAttribute"))
            {
                if (registerAttribute == null || !registerAttribute.HasConstructorArguments)
                {
                    continue;
                }

                var constructorParameters = registerAttribute.Constructor.Parameters.ToArray();
                var constructorArguments  = registerAttribute.ConstructorArguments.ToArray();

                for (int i = 0; i < constructorArguments.Length; i++)
                {
                    switch (constructorParameters [i].Name)
                    {
                    case "name":
                        name = constructorArguments [i].Value.ToString();
                        break;

                    case "signature":
                        signature = constructorArguments [i].Value.ToString();
                        break;
                    }
                }

                if ((string.IsNullOrEmpty(name) || string.IsNullOrEmpty(signature)) && constructorArguments.Length != 3)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(name))
                {
                    name = constructorArguments [0].Value.ToString();
                }

                if (string.IsNullOrEmpty(signature))
                {
                    signature = constructorArguments [1].Value.ToString();
                }

                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(signature))
                {
                    continue;
                }

                methodName = MarshalMemberBuilder.GetMarshalMethodName(name, signature);
                name       = $"n_{name}";

                return(true);
            }

            return(false);
        }