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()); } }
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 }; } }
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()); } }
public SSInterpretPropertyInfo AddProperty(string id, BasePropertyDeclarationSyntax property) { var propertyInfo = new SSInterpretPropertyInfo(this, Runner, id, property) { IsStatic = property.Modifiers.IsStatic(), DeclaringClass = this, AccessModifier = AccessModifierParser.Parse(property.Modifiers) }; Properties.Add(id, propertyInfo); return(propertyInfo); }
public SSFieldInfo AddField(string id, FieldDeclarationSyntax field, VariableDeclaratorSyntax declarator) { var fieldInfo = new SSInterpretFieldInfo(this) { Id = id, FieldType = Runner.Resolver.GetType($"{field.Declaration.Type}"), IsStatic = field.Modifiers.IsStatic() | field.Modifiers.IsConst(), IsConst = field.Modifiers.IsConst(), Field = field, DeclaringClass = this, Declartor = declarator, AccessModifier = AccessModifierParser.Parse(field.Modifiers) }; Fields.Add(id, fieldInfo); return(fieldInfo); }
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); }
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()); } }
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); } }