Example #1
0
        VariableInfo ResolveMember(object obj, string name, out object res)
        {
            res = null;
            Type type = null;

            if (obj is ILTypeInstance)
            {
                type = ((ILTypeInstance)obj).Type.ReflectionType;
            }
            else if (obj is Enviorment.CrossBindingAdaptorType)
            {
                type = ((Enviorment.CrossBindingAdaptorType)obj).ILInstance.Type.ReflectionType;
            }
            else
            {
                type = obj.GetType();
            }
            var fi = type.GetField(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (fi != null)
            {
                res = fi.GetValue(obj);
                VariableInfo info = VariableInfo.FromObject(res);

                info.Address     = 0;
                info.Name        = name;
                info.Type        = VariableTypes.FieldReference;
                info.TypeName    = fi.FieldType.FullName;
                info.IsPrivate   = fi.IsPrivate;
                info.IsProtected = fi.IsFamily;
                info.Expandable  = res != null && !fi.FieldType.IsPrimitive;

                return(info);
            }
            else
            {
                var pi = type.GetProperty(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                if (pi != null)
                {
                    res = pi.GetValue(obj, null);
                    VariableInfo info = VariableInfo.FromObject(res);

                    info.Address     = 0;
                    info.Name        = name;
                    info.Type        = VariableTypes.PropertyReference;
                    info.TypeName    = pi.PropertyType.FullName;
                    info.IsPrivate   = pi.GetGetMethod(true).IsPrivate;
                    info.IsProtected = pi.GetGetMethod(true).IsFamily;
                    info.Expandable  = res != null && !pi.PropertyType.IsPrimitive;
                    return(info);
                }
            }
            return(VariableInfo.GetCannotFind(name));
        }
Example #2
0
        internal unsafe VariableInfo ResolveVariable(int threadHashCode, VariableReference variable, out object res)
        {
            ILIntepreter intepreter;

            res = null;
            if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter))
            {
                if (variable != null)
                {
                    switch (variable.Type)
                    {
                    case VariableTypes.Normal:
                    {
                        StackObject *ptr = (StackObject *)variable.Address;
                        object       obj = StackObject.ToObject(ptr, AppDomain, intepreter.Stack.ManagedStack);
                        if (obj != null)
                        {
                            //return ResolveMember(obj, name, out res);
                            res = obj;
                            return(null);
                        }
                        else
                        {
                            return(VariableInfo.Null);
                        }
                    }

                    case VariableTypes.FieldReference:
                    case VariableTypes.PropertyReference:
                    {
                        object obj;
                        if (variable.Parent != null)
                        {
                            var info = ResolveVariable(threadHashCode, variable.Parent, out obj);
                            if (obj != null)
                            {
                                return(ResolveMember(obj, variable.Name, out res));
                            }
                            else
                            {
                                return(VariableInfo.NullReferenceExeption);
                            }
                        }
                        else
                        {
                            var frame = intepreter.Stack.Frames.Peek();
                            var m     = frame.Method;
                            if (m.HasThis)
                            {
                                var addr = Minus(frame.LocalVarPointer, m.ParameterCount + 1);
                                var v    = StackObject.ToObject(addr, intepreter.AppDomain, intepreter.Stack.ManagedStack);
                                return(ResolveMember(v, variable.Name, out res));
                            }
                            else
                            {
                                return(VariableInfo.GetCannotFind(variable.Name));
                            }
                        }
                    }

                    case VariableTypes.IndexAccess:
                    {
                        return(ResolveIndexAccess(threadHashCode, variable.Parent, variable.Parameters[0], out res));
                    }

                    case VariableTypes.Integer:
                    {
                        res = variable.Offset;
                        return(VariableInfo.GetInteger(variable.Offset));
                    }

                    case VariableTypes.String:
                    {
                        res = variable.Name;
                        return(VariableInfo.GetString(variable.Name));
                    }

                    case VariableTypes.Boolean:
                    {
                        if (variable.Offset == 1)
                        {
                            res = true;
                            return(VariableInfo.True);
                        }
                        else
                        {
                            res = false;
                            return(VariableInfo.False);
                        }
                    }

                    case VariableTypes.Null:
                    {
                        res = null;
                        return(VariableInfo.Null);
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    return(VariableInfo.NullReferenceExeption);
                }
            }
            else
            {
                return(VariableInfo.NullReferenceExeption);
            }
        }