Beispiel #1
0
        /// <summary>
        /// Create instance RuntimeMethodEncoding class from instance of Objective-C NSMethodSignature class.
        /// </summary>
        /// <param name="methodSignature">Objective-C NSMethodSignature class instance.</param>
        /// <returns>RuntimeMethodEncoding intialized from NSMethodSignature encoding.</returns>
        public static RuntimeMethodEncoding FromNSMethodSignature(RuntimeObject methodSignature)
        {
            if (methodSignature == RuntimeObject.Null)
            {
                return(null);
            }

            var argumentsCount = methodSignature.InvokeUInt32("numberOfArguments");
            var signatureTypes = new Type[argumentsCount + 1];

            signatureTypes[0] = DecodeType(( char )Marshal.ReadByte(methodSignature.InvokeIntPtr("methodReturnType")));

            for (int i = 0; i < argumentsCount; i++)
            {
                signatureTypes[i + 1] = DecodeType(( char )Marshal.ReadByte(methodSignature.InvokeIntPtr("getArgumentTypeAtIndex:", i)));
            }

            var result = new RuntimeMethodEncoding(signatureTypes);

            Tracer.Information("Generate encoding from NSSignature: {0}", result);

            return(result);
        }