示例#1
0
        private SSMethodInfo[] _GetMethods()
        {
            if (IsCompiledType)
            {
                return(CompiledType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
                       .Where(x => x.IsPrivate == false)
                       .Select(x => new SSMethodInfo(x)
                {
                    Id = x.Name,
                    IsStatic = x.IsStatic,
                    AccessModifier = AccessModifierParser.Get(x)
                })
                       .ToArray());
            }
            else
            {
                if (Parent == null)
                {
                    return(InterpretKlass.GetMethods());
                }

                return(Parent.GetMethods()
                       .Concat(InterpretKlass.GetMethods())
                       .GroupBy(x => x.Signature)
                       .Select(x => x.Last())
                       .ToArray());
            }
        }
示例#2
0
        internal SSCompiledMethodInfo(MethodInfo methodInfo)
        {
            this.Id             = methodInfo.Name;
            this.Signature      = MemberSignature.GetSignature(methodInfo);
            this.DeclaringType  = HybTypeCache.GetHybType(methodInfo.DeclaringType);
            this.Target         = new Invokable(methodInfo);
            this.IsStatic       = methodInfo.IsStatic;
            this.AccessModifier = AccessModifierParser.Get(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
                };
            }
        }
示例#3
0
        public SSMethodInfo[] GetMethods(string id)
        {
            if (IsCompiledType)
            {
                return(Obj.GetType().GetMethods()
                       .Where(x => x.Name == id)
                       .Select(x => new SSMethodInfo(x)
                {
                    Id = x.Name,
                    IsStatic = x.IsStatic,
                    AccessModifier = AccessModifierParser.Get(x)
                })
                       .ToArray());
            }
            else
            {
                if (Parent == null)
                {
                    return(Klass.GetMethods(id));
                }

                return(Parent.GetMethods(id)
                       .Concat(Klass.GetMethods(id))
                       .ToArray());
            }
        }
示例#4
0
 private SSMethodInfo[] _GetStaticMethods()
 {
     if (IsCompiledType)
     {
         return(CompiledType.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                .Select(x => new SSMethodInfo(x)
         {
             Id = x.Name,
             IsStatic = x.IsStatic,
             AccessModifier = AccessModifierParser.Get(x)
         })
                .ToArray());
     }
     else
     {
         if (Parent == null)
         {
             return(InterpretKlass.GetMethods());
         }
         return(InterpretKlass.GetMethods()
                .Concat(Parent.GetStaticMethods())
                .ToArray());
     }
 }
示例#5
0
        internal bool GetPropertyOrField(string id, out HybInstance value, AccessLevel level)
        {
            if (IsCompiledType)
            {
                var p = Obj.GetType()
                        .GetProperty(id, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                if (p != null)
                {
                    var mod = AccessModifierParser.Get(p.GetMethod);
                    if (mod.IsAcceesible(level) == false)
                    {
                        throw new SemanticViolationException($"Invalid access: {id}");
                    }

                    value = HybInstance.Object(p.GetValue(Obj));
                    return(true);
                }

                var f = Obj.GetType()
                        .GetField(id, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                if (f != null)
                {
                    var mod = AccessModifierParser.Get(f);
                    if (mod.IsAcceesible(level) == false)
                    {
                        throw new SemanticViolationException($"Invalid access: {id}");
                    }

                    value = HybInstance.Object(f.GetValue(Obj));
                    return(true);
                }

                value = null;
                return(false);
            }
            else
            {
                if (Klass.HasProperty(id, MemberFlag.Member))
                {
                    var p = Klass.GetProperty(id);
                    if (p.AccessModifier.IsAcceesible(level) == false)
                    {
                        throw new SemanticViolationException($"Invalid access: {id}");
                    }
                    Runner.BindThis(this);
                    value = p.GetMethod.Invoke(this, new HybInstance[] { });
                    return(true);
                }

                if (Klass.HasField(id, MemberFlag.Member))
                {
                    var f = Klass.GetField(id);
                    if (f.AccessModifier.IsAcceesible(level) == false)
                    {
                        throw new SemanticViolationException($"Invalid access: {id}");
                    }
                    value = Fields.Get(id);
                    return(true);
                }

                if (Parent != null)
                {
                    return(Parent.GetPropertyOrField(id, out value, level));
                }

                value = null;
                return(false);
            }
        }