public static IEnumerable <Parameter> GetParameters(this MethodDefinition m, CustomAttribute regatt)
        {
            var jnisig = (string)(regatt.ConstructorArguments.Count > 1 ? regatt.ConstructorArguments [1].Value : regatt.Properties.First(p => p.Name == "JniSignature").Argument.Value);
            var types  = jnisig == null ? null : JavaNativeTypeManager.FromSignature(jnisig);
            var e      = types?.GetEnumerator();

            foreach (var p in m.Parameters)
            {
                if (e != null && !e.MoveNext())
                {
                    e = null;
                }
                // Here we do some tricky thing:
                // Both java.io.InputStream and java.io.OutputStream could be mapped to
                // System.IO.Stream. And when there is Stream in parameters, we have to
                // determine which direction of the Stream it was - in or out.
                // To do that, we inspect JNI Signature to handle that.
                //
                // We could *always* use this JNI information, *IF* there were no
                // int->enum conversion. Sadly this is not true, we still have to expect
                // custom enum types and cannot simply use JNI signature here.
                var rawtype   = e?.Current.Type;
                var type      = p.ParameterType.FullName == "System.IO.Stream" && e != null ? e.Current.Type : null;
                var isNotNull = p.GetTypeNullability(m) == Nullability.NotNull;

                yield return(CecilApiImporter.CreateParameter(p, type, rawtype, isNotNull));
            }
        }
Exemple #2
0
            public Signature(string name, string signature, string connector, string managedParameters, string outerType, string superCall)
            {
                ManagedParameters = managedParameters;
                JniSignature      = signature;
                Method            = "n_" + name + ":" + signature + ":" + connector;
                Name = name;

                var    jnisig = signature;
                int    closer = jnisig.IndexOf(")");
                string ret    = jnisig.Substring(closer + 1);

                retval = JavaNativeTypeManager.Parse(ret).Type;
                string jniparms = jnisig.Substring(1, closer - 1);

                if (string.IsNullOrEmpty(jniparms) && string.IsNullOrEmpty(superCall))
                {
                    return;
                }
                var  parms = new StringBuilder();
                var  scall = new StringBuilder();
                var  acall = new StringBuilder();
                bool first = true;
                int  i     = 0;

                foreach (JniTypeName jti in JavaNativeTypeManager.FromSignature(jniparms))
                {
                    if (outerType != null)
                    {
                        acall.Append(outerType).Append(".this");
                        outerType = null;
                        continue;
                    }
                    string parmType = jti.Type;
                    if (!first)
                    {
                        parms.Append(", ");
                        scall.Append(", ");
                        acall.Append(", ");
                    }
                    first = false;
                    parms.Append(parmType).Append(" p").Append(i);
                    scall.Append("p").Append(i);
                    acall.Append("p").Append(i);
                    ++i;
                }
                this.parms        = parms.ToString();
                this.call         = superCall != null ? superCall : scall.ToString();
                this.ActivateCall = acall.ToString();
            }