Пример #1
0
        private static IValue[] GetArgsToPass(ArrayImpl arguments, MethodInfo methInfo)
        {
            var argsToPass = new List <IValue>();

            if (arguments != null)
            {
                argsToPass.AddRange(arguments);
            }

            if (methInfo.ArgCount < argsToPass.Count)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            for (int i = 0; i < argsToPass.Count; i++)
            {
                if (!methInfo.Params[i].IsByValue)
                {
                    argsToPass[i] = Variable.Create(argsToPass[i], $"reflectorArg{i}");
                }
            }
            while (argsToPass.Count < methInfo.ArgCount)
            {
                argsToPass.Add(null);
            }

            return(argsToPass.ToArray());
        }
Пример #2
0
        private static IEnumerable <MethodInfo> ConvertToOsMethods(IEnumerable <System.Reflection.MethodInfo> source)
        {
            var dest = new List <MethodInfo>();

            foreach (var methodInfo in source)
            {
                var osMethod = new MethodInfo();
                osMethod.Name        = methodInfo.Name;
                osMethod.Alias       = null;
                osMethod.IsExport    = methodInfo.IsPublic;
                osMethod.IsFunction  = methodInfo.ReturnType != typeof(void);
                osMethod.Annotations = GetAnnotations(methodInfo.GetCustomAttributes <UserAnnotationAttribute>());

                var methodParameters = methodInfo.GetParameters();
                var osParams         = new ParameterDefinition[methodParameters.Length];
                osMethod.Params = osParams;
                for (int i = 0; i < osParams.Length; i++)
                {
                    var parameterInfo = methodParameters[i];
                    var osParam       = new ParameterDefinition();
                    osParam.Name              = parameterInfo.Name;
                    osParam.IsByValue         = parameterInfo.GetCustomAttribute <ByRefAttribute>() != null;
                    osParam.HasDefaultValue   = parameterInfo.HasDefaultValue;
                    osParam.DefaultValueIndex = -1;
                    osParam.Annotations       = GetAnnotations(parameterInfo.GetCustomAttributes <UserAnnotationAttribute>());
                    osParams[i] = osParam;
                }
                dest.Add(osMethod);
            }

            return(dest);
        }
Пример #3
0
        public IEnumerable <MethodInfo> GetMethods()
        {
            var array = new MethodInfo[_methods.Count];

            for (var i = 0; i < _methods.Count; i++)
            {
                array[i] = _methods.GetMethodInfo(i);
            }

            return(array);
        }
Пример #4
0
        private static IEnumerable <MethodInfo> ConvertToOsMethods(IEnumerable <System.Reflection.MethodInfo> source)
        {
            var dest = new List <MethodInfo>();

            foreach (var methodInfo in source)
            {
                var osMethod = new MethodInfo();
                osMethod.Name        = methodInfo.Name;
                osMethod.Alias       = null;
                osMethod.IsExport    = methodInfo.IsPublic;
                osMethod.IsFunction  = methodInfo.ReturnType != typeof(void);
                osMethod.Annotations = GetAnnotations(methodInfo.GetCustomAttributes <UserAnnotationAttribute>());

                var methodParameters = methodInfo.GetParameters();
                var osParams         = new ParameterDefinition[methodParameters.Length];
                osMethod.Params = osParams;
                for (int i = 0; i < osParams.Length; i++)
                {
                    var parameterInfo = methodParameters[i];
                    var osParam       = new ParameterDefinition();
                    osParam.Name              = parameterInfo.Name;
                    osParam.IsByValue         = parameterInfo.GetCustomAttribute <ByRefAttribute>() != null;
                    osParam.HasDefaultValue   = parameterInfo.HasDefaultValue;
                    osParam.DefaultValueIndex = -1;

                    // On Mono 5.20 we can't use GetCustomAttributes<T> because it fails with InvalidCast.
                    // Here's a workaround with home-made attribute Type filter.
                    var attributes = parameterInfo.GetCustomAttributes()
                                     .OfType <UserAnnotationAttribute>();

                    osParam.Annotations = GetAnnotations(attributes);
                    osParams[i]         = osParam;
                }
                dest.Add(osMethod);
            }

            return(dest);
        }