Ejemplo n.º 1
0
        public IEnumerable <Parameter> GetParameters(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 : JniType.FromSignature(jnisig);
            var e      = types != null?types.GetEnumerator() : null;

            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 != null ? e.Current.Type : null;
                var type    = p.ParameterType.FullName == "System.IO.Stream" && e != null ? e.Current.Type : null;
                yield return(Parameter.FromManagedParameter(p, type, rawtype));
            }
        }
Ejemplo n.º 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 = JniType.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 (JniType jti in JniType.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();
            }