bool Format(DbgDotNetValue value, TypeState typeState, DisplayPart[] displayParts)
        {
            if (displayParts.Length == 0)
            {
                return(false);
            }

            var evaluator = evalInfo.Context.GetDebuggerDisplayAttributeEvaluator();

            foreach (var part in displayParts)
            {
                if ((part.Flags & DisplayPartFlags.EvaluateText) == 0)
                {
                    output.Write(DbgTextColor.DebuggerDisplayAttributeEval, part.Text);
                }
                else
                {
                    var eeState = typeState.GetExpressionEvaluatorState(evalInfo.Context.Language.ExpressionEvaluator, part.Text);
                    DbgDotNetEvalResult evalRes = default;
                    try {
                        var evalInfo2 = new DbgEvaluationInfo(typeState.TypeContext !, evalInfo.Frame, evalInfo.CancellationToken);
                        evalRes = evaluator.Evaluate(evalInfo2, value, part.Text, DbgEvaluationOptions.Expression, eeState);
                        if (evalRes.Error is not null)
                        {
                            output.Write(DbgTextColor.Error, "<<<");
                            output.Write(DbgTextColor.Error, evalRes.Error);
                            output.Write(DbgTextColor.Error, ">>>");
                        }
                        else
                        {
                            // Prevent recursive calls
                            var options = this.options | DbgValueFormatterOptions.NoDebuggerDisplay;
                            options &= ~DbgValueFormatterOptions.NoStringQuotes;
                            options  = PredefinedFormatSpecifiers.GetValueFormatterOptions(evalRes.FormatSpecifiers, options);
                            languageFormatter.FormatValue(evalInfo, output, evalRes.Value !, options, cultureInfo);
                        }
                    }
                    finally {
                        if (evalRes.Value != value)
                        {
                            evalRes.Value?.Dispose();
                        }
                    }
                }
            }

            return(true);
        }
Example #2
0
        public bool Format(DbgDotNetValue value)
        {
            var typeState = GetOrCreateTypeState(value.Type, context.Language);

            if (typeState.DisplayParts.Length == 0)
            {
                return(false);
            }

            var evaluator = context.GetDebuggerDisplayAttributeEvaluator();

            foreach (var part in typeState.DisplayParts)
            {
                if ((part.Flags & DisplayPartFlags.EvaluateText) == 0)
                {
                    output.Write(BoxedTextColor.DebuggerDisplayAttributeEval, part.Text);
                }
                else
                {
                    object eeState = typeState.GetExpressionEvaluatorState(context.Language.ExpressionEvaluator, part.Text);
                    DbgDotNetEvalResult evalRes = default;
                    try {
                        evalRes = evaluator.Evaluate(typeState.TypeContext, frame, value, part.Text, DbgEvaluationOptions.Expression, eeState, cancellationToken);
                        if (evalRes.Error != null)
                        {
                            output.Write(BoxedTextColor.Error, "<<<");
                            output.Write(BoxedTextColor.Error, evalRes.Error);
                            output.Write(BoxedTextColor.Error, ">>>");
                        }
                        else
                        {
                            // Prevent recursive calls by disabling func-eval
                            var options = this.options & ~(DbgValueFormatterOptions.FuncEval | DbgValueFormatterOptions.ToString);
                            if ((part.Flags & DisplayPartFlags.Decimal) != 0)
                            {
                                options |= DbgValueFormatterOptions.Decimal;
                            }
                            else if ((part.Flags & DisplayPartFlags.Hexadecimal) != 0)
                            {
                                options &= ~DbgValueFormatterOptions.Decimal;
                            }
                            if ((part.Flags & DisplayPartFlags.NoQuotes) != 0)
                            {
                                options |= DbgValueFormatterOptions.NoStringQuotes;
                            }
                            else
                            {
                                options &= ~DbgValueFormatterOptions.NoStringQuotes;
                            }

                            languageFormatter.FormatValue(context, output, frame, evalRes.Value, options, cultureInfo, cancellationToken);
                        }
                    }
                    finally {
                        if (evalRes.Value != value)
                        {
                            evalRes.Value?.Dispose();
                        }
                    }
                }
            }

            return(true);
        }