Esempio n. 1
0
        internal object EvaluateExpression(string expressionString)
        {
            // This is to shortcircuit a common case where
            // internally, vsdebugger calls our EE with literal "0"
            int intResult;

            if (int.TryParse(expressionString, out intResult))
            {
                return(intResult);
            }

            // At refresh, Expression Evaluator may re-evaluate locals/arguments.
            // To speed up the process, locals/arguments are cached.
            LocalInfo cachedLocalInfo = null;

            if (this.cachedLocalInfos != null && this.cachedLocalInfos.TryGetValue(expressionString, out cachedLocalInfo))
            {
                return(cachedLocalInfo);
            }

            Activity activity = activityInstance.Activity;
            LocationReferenceEnvironment locationReferenceEnvironment = activity.PublicEnvironment;

            // a temporary context for EvaluateExpression
            // We're not using the executor so it's ok that it's null
            CodeActivityContext context = new CodeActivityContext(activityInstance, null);

            object result;

            try
            {
                // First try as R-Value
                if (!TryEvaluateExpression(expressionString, null, locationReferenceEnvironment, context, out result))
                {
                    return(SR.DebugInfoCannotEvaluateExpression(expressionString));
                }
            }
            catch (Exception ex)
            {
                // ---- all exceptions, this exception is generated by user typing input in either
                // Watch window or Immediate windows.  Exception should not affect the current runtime.
                // Except for fatal exception.
                if (Fx.IsFatal(ex))
                {
                    throw;
                }
                context.Dispose();
                return(SR.DebugInfoCannotEvaluateExpression(expressionString));
            }

            // Now try expression as an L-Value if possible.
            try
            {
                object resultLocation;
                if (TryEvaluateExpression(expressionString, result.GetType(), locationReferenceEnvironment, context, out resultLocation))
                {
                    LocalInfo localInfo = new LocalInfo()
                    {
                        Name     = expressionString,
                        Location = resultLocation as Location
                    };
                    this.cachedLocalInfos[expressionString] = localInfo;
                    return(localInfo);
                }
            }
            catch (Exception ex)
            {
                // ---- all exceptions, this exception is generated by user typing input in either
                // Watch window or Immediate windows.  Exception should not affect the current runtime.
                // Except for fatal exception.
                if (Fx.IsFatal(ex))
                {
                    throw;
                }
            }
            finally
            {
                context.Dispose();
            }
            return(result);
        }
Esempio n. 2
0
        internal object EvaluateExpression(string expressionString)
        {
            // This is to shortcircuit a common case where 
            // internally, vsdebugger calls our EE with literal "0"            
            int intResult;
            if (int.TryParse(expressionString, out intResult))
            {
                return intResult;
            }

            // At refresh, Expression Evaluator may re-evaluate locals/arguments.
            // To speed up the process, locals/arguments are cached.
            LocalInfo cachedLocalInfo = null;
            if (this.cachedLocalInfos != null && this.cachedLocalInfos.TryGetValue(expressionString, out cachedLocalInfo))
            {
                return cachedLocalInfo;
            }

            Activity activity = activityInstance.Activity;
            LocationReferenceEnvironment locationReferenceEnvironment = activity.PublicEnvironment;

            // a temporary context for EvaluateExpression
            // We're not using the executor so it's ok that it's null
            CodeActivityContext context = new CodeActivityContext(activityInstance, null);

            object result;
            try
            {
                // First try as R-Value
                if (!TryEvaluateExpression(expressionString, null, locationReferenceEnvironment, context, out result))
                {
                    return SR.DebugInfoCannotEvaluateExpression(expressionString);
                }
            }
            catch (Exception ex)
            {
                // ---- all exceptions, this exception is generated by user typing input in either
                // Watch window or Immediate windows.  Exception should not affect the current runtime.
                // Except for fatal exception.
                if (Fx.IsFatal(ex))
                {
                    throw;
                }
                context.Dispose();
                return SR.DebugInfoCannotEvaluateExpression(expressionString);
            }

            // Now try expression as an L-Value if possible.
            try
            {
                object resultLocation;
                if (TryEvaluateExpression(expressionString, result.GetType(), locationReferenceEnvironment, context, out resultLocation))
                {
                    LocalInfo localInfo = new LocalInfo()
                                            {
                                                Name = expressionString,
                                                Location = resultLocation as Location
                                            };
                    this.cachedLocalInfos[expressionString] = localInfo;
                    return localInfo;
                }
            }
            catch (Exception ex)
            {
                // ---- all exceptions, this exception is generated by user typing input in either
                // Watch window or Immediate windows.  Exception should not affect the current runtime.
                // Except for fatal exception.
                if (Fx.IsFatal(ex))
                {
                    throw;
                }
            }
            finally
            {
                context.Dispose();
            }
            return result;
        }