Ejemplo n.º 1
0
        internal SSMethodInfo(MethodInfo methodInfo)
        {
            this.Id            = methodInfo.Name;
            this.Signature     = MemberSignature.GetSignature(methodInfo);
            this.DeclaringType = HybTypeCache.GetHybType(methodInfo.DeclaringType);
            this.Target        = new Invokable(methodInfo);

            this.ReturnType = HybTypeCache.GetHybType(methodInfo.ReturnType);
            this.IsVaArg    =
                methodInfo.GetParameters().LastOrDefault()
                ?.IsDefined(typeof(ParamArrayAttribute), false) ?? false;

            var ps = methodInfo.GetParameters();

            this.Parameters = new SSParamInfo[ps.Length];
            for (int i = 0; i < this.Parameters.Length; i++)
            {
                var p = ps[i];
                this.Parameters[i] = new SSParamInfo()
                {
                    Id           = p.Name,
                    DefaultValue = p.HasDefaultValue ? HybInstance.Object(p.DefaultValue) : null,
                    IsParams     = this.IsVaArg && i == this.Parameters.Length - 1
                };
            }
        }
Ejemplo n.º 2
0
        internal SSMethodInfo(Runner runner, string id, HybType declaringType, BaseMethodDeclarationSyntax declaration)
        {
            this.Id        = id;
            this.Signature = MemberSignature.GetSignature(
                runner.Resolver, id, declaration);
            this.DeclaringType = declaringType;
            this.Target        = new Invokable(this, runner, declaration);

            if (declaration is MethodDeclarationSyntax md)
            {
                this.ReturnType = runner.Resolver.GetType($"{md.ReturnType}");
            }
            this.IsVaArg =
                declaration.ParameterList.Parameters.LastOrDefault()
                ?.Modifiers.IsParams() ?? false;

            this.Parameters = new SSParamInfo[declaration.ParameterList.Parameters.Count];
            for (int i = 0; i < this.Parameters.Length; i++)
            {
                var p = declaration.ParameterList.Parameters[i];
                this.Parameters[i] = new SSParamInfo()
                {
                    Id           = p.Identifier.Text,
                    DefaultValue = p.Default != null?runner.RunExpression(p.Default.Value) : null,
                                       IsParams = p.Modifiers.IsParams()
                };
            }
        }
Ejemplo n.º 3
0
        public SSInterpretMethodInfo AddMethod(string id, BaseMethodDeclarationSyntax method, JumpDestination[] jumps)
        {
            EnsureMethodKey(id);

            var signature = MemberSignature.GetSignature(
                Runner.Resolver, id, method);

            var methodInfo = new SSInterpretMethodInfo(Runner, id, Type, method)
            {
                Id             = id,
                IsStatic       = method.Modifiers.IsStatic(),
                DeclaringClass = this,
                Declaration    = method,
                Jumps          = jumps,

                AccessModifier = AccessModifierParser.Parse(method.Modifiers)
            };

            Methods[id].RemoveAll(x => x.Signature == signature);
            Methods[id].Add(methodInfo);

            return(methodInfo);
        }