Пример #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 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);
     }
 }
 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());
        }