Пример #1
0
        public static ObjectValue CreateEvaluationException(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, EvaluatorExceptionThrownException exception,
                                                            ObjectValueFlags flags = ObjectValueFlags.None)
        {
            var error = CreateError(source, path, exception.ExceptionTypeName, "Exception was thrown", flags);
            var exceptionReference = LiteralValueReference.CreateTargetObjectLiteral(ctx, "Exception", exception.Exception);
            var exceptionValue     = exceptionReference.CreateObjectValue(ctx.Options);

            error.children = new List <ObjectValue> {
                exceptionValue
            };
            return(error);
        }
 public override ValueReference GetThisReference(EvaluationContext ctx)
 {
     try {
         SoftEvaluationContext cx = (SoftEvaluationContext)ctx;
         if (cx.Frame.Method.IsStatic)
         {
             return(null);
         }
         Value val = cx.Frame.GetThis();
         return(LiteralValueReference.CreateTargetObjectLiteral(ctx, "this", val));
     } catch (AbsentInformationException) {
         return(null);
     }
 }
        public static ValueReference CreateIndexerValueReference(MdbEvaluationContext ctx, TargetObject target, TargetObject[] index)
        {
            TargetFundamentalObject mstr = target as TargetFundamentalObject;

            if (mstr != null && mstr.TypeName == "string")
            {
                // Special case for strings
                string name = "[" + ctx.Evaluator.TargetObjectToExpression(ctx, index[0]) + "]";
                string val  = (string)mstr.GetObject(ctx.Thread);
                object oo   = ctx.Adapter.TargetObjectToObject(ctx, index[0]);
                int    idx  = (int)Convert.ChangeType(oo, typeof(int));
                return(LiteralValueReference.CreateObjectLiteral(ctx, name, val [idx]));
            }

            TargetStructObject sob = target as TargetStructObject;

            if (sob == null)
            {
                return(null);
            }

            TargetPropertyInfo indexerProp = null;

            foreach (MemberReference mem in ObjectUtil.GetTypeMembers(ctx, target.Type, false, true, true, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static))
            {
                if (mem.Member.IsStatic)
                {
                    continue;
                }
                if (mem.Member is TargetPropertyInfo)
                {
                    TargetPropertyInfo prop = (TargetPropertyInfo)mem.Member;
                    if (prop.CanRead && prop.Getter.ParameterTypes.Length == 1)
                    {
                        indexerProp = prop;
                        break;
                    }
                }
            }
            if (indexerProp != null)
            {
                return(new IndexerValueReference(ctx, sob, index, indexerProp));
            }
            else
            {
                return(null);
            }
        }
 public override ValueReference GetCurrentException(EvaluationContext ctx)
 {
     try {
         SoftEvaluationContext cx  = (SoftEvaluationContext)ctx;
         ObjectMirror          exc = cx.Session.GetExceptionObject(cx.Thread);
         if (exc != null)
         {
             return(LiteralValueReference.CreateTargetObjectLiteral(ctx, ctx.Options.CurrentExceptionTag, exc));
         }
         else
         {
             return(null);
         }
     } catch (AbsentInformationException) {
         return(null);
     }
 }
        public override ValueReference Evaluate(EvaluationContext ctx, string exp, object expectedType)
        {
            var asType = expectedType as Type;

            if (asType == null)
            {
                // Cannot do anything.
            }
            else if (asType == typeof(string))
            {
                exp = VSCodeObjectSource.Unquote(exp);
                return(LiteralValueReference.CreateObjectLiteral(ctx, exp, exp));
            }
            else if (asType.IsPrimitive)
            {
                return(LiteralValueReference.CreateObjectLiteral(ctx, exp, exp));
            }
            return(base.Evaluate(ctx, exp, expectedType));
        }
 protected ObjectValue CreateObjectValue(string name, Value value, IEvaluationOptions options)
 {
     return(LiteralValueReference.CreateTargetObjectLiteral(Adaptor, Context, name, value)
            .CreateObjectValue(options));
 }
        protected override ObjectValue[] GetChildrenSafe(ObjectPath path, int index, int count,
                                                         IEvaluationOptions options)
        {
            var allocatorTempObject     = Evaluate("global::Unity.Collections.Allocator.Temp");
            var componentDataType       = GetType("Unity.Entities.IComponentData").NotNull();
            var sharedComponentDataType = GetType("Unity.Entities.ISharedComponentData").NotNull();

            var entityManagerGetComponentTypesMethod      = myEntityManagerType.GetMethod("GetComponentTypes");
            var entityManagerGetSharedComponentDataMethod = myEntityManagerType.GetMethod("GetSharedComponentData");
            var entityManagerGetComponentDataMethod       = myEntityManagerType.GetMethod("GetComponentData");

            var componentTypesArray = Invoke(entityManagerGetComponentTypesMethod, myEntityManagerType,
                                             myEntityManagerObject, myEntityObject, allocatorTempObject.Value).NotNull();
            var componentTypesArrayLength =
                (PrimitiveValue)Adaptor.GetMember(Context, null, componentTypesArray, "Length").Value;

            var numberOfComponentTypes = (int)componentTypesArrayLength.Value;

            var objectValues = new List <ObjectValue>();

            for (var currentIndex = 0; currentIndex < numberOfComponentTypes; currentIndex++)
            {
                try
                {
                    var currentIndexValue = Adaptor.CreateValue(Context, currentIndex);
                    var currentComponent  = Adaptor
                                            .GetIndexerReference(Context, componentTypesArray, new[] { currentIndexValue }).Value;
                    var currentComponentType = currentComponent.Type;

                    var getManagedTypeMethod    = currentComponentType.GetMethod("GetManagedType");
                    var dataManagedType         = Invoke(getManagedTypeMethod, currentComponentType, currentComponent);
                    var dataManagedTypeFullName =
                        ((StringMirror)Adaptor.GetMember(Context, null, dataManagedType, "FullName").Value).Value;
                    var dataManagedTypeShortName =
                        ((StringMirror)Adaptor.GetMember(Context, null, dataManagedType, "Name").Value).Value;
                    var dataType = GetType(dataManagedTypeFullName);

                    MethodMirror getComponentDataMethod;
                    if (componentDataType.IsAssignableFrom(dataType))
                    {
                        getComponentDataMethod = entityManagerGetComponentDataMethod;
                    }
                    else if (sharedComponentDataType.IsAssignableFrom(dataType))
                    {
                        getComponentDataMethod = entityManagerGetSharedComponentDataMethod;
                    }
                    else
                    {
                        ourLogger.Warn("Unknown type of component data: {0}", dataManagedTypeFullName);
                        continue;
                    }

                    var getComponentDataMethodWithTypeArgs =
                        getComponentDataMethod.MakeGenericMethod(new[] { dataType });
                    var result = Invoke(getComponentDataMethodWithTypeArgs, myEntityManagerType,
                                        myEntityManagerObject, myEntityObject);
                    objectValues.Add(LiteralValueReference
                                     .CreateTargetObjectLiteral(Adaptor, Context, dataManagedTypeShortName, result)
                                     .CreateObjectValue(options));
                }
                catch (Exception e)
                {
                    ourLogger.Error(e, "Failed to fetch parameter {0} of entity {1}", currentIndex, myEntityObject);
                }
            }

            return(objectValues.ToArray());
        }