Exemplo n.º 1
0
        public override IValuePresentation PresentValue(IStringValueRole <TValue> valueRole, IMetadataTypeLite instanceType,
                                                        IPresentationOptions options, IUserDataHolder dataHolder, CancellationToken token)
        {
            // Note that ValueFlags.IsString will add the "View" link to see a string in a popup. We don't need this
            var text = valueRole.GetString();

            return(SimplePresentation.CreateSuccess(ValuePresentationPart.Default(text),
                                                    valueRole.ValueReference.DefaultFlags | ValueFlags.NoChildren, instanceType, text));
        }
        public override IValuePresentation PresentValue(IStringValueRole <TValue> valueRole, IMetadataTypeLite instanceType,
                                                        IPresentationOptions options, IUserDataHolder dataHolder, CancellationToken token)
        {
            // Present the value's string as plain text, without any syntax highlighting or quote handling. Don't use
            // ValueFlags.IsString, as it will add an unnecessary "View" link - our text is always short
            var text = valueRole.GetString();

            return(SimplePresentation.CreateSuccess(ValuePresentationPart.Default(text),
                                                    valueRole.ValueReference.DefaultFlags | ValueFlags.NoChildren, instanceType, text));
        }
        // Return null to allow other providers a chance. If we throw EvaluatorException, it will be presented to the
        // user. OperationCancelledException will be logged and we move on to the next presenter. Any other exception
        // will leak
        public override IValuePresentation PresentValue(IObjectValueRole <TValue> valueRole,
                                                        IMetadataTypeLite instanceType,
                                                        IPresentationOptions options,
                                                        IUserDataHolder dataHolder,
                                                        CancellationToken token)
        {
            var debuggerDisplayString = dataHolder.GetData(ourDebuggerDisplayStringKey);

            try
            {
                var valueReference    = valueRole.ValueReference;
                var thisObj           = valueReference.GetValue(options);
                var evaluationOptions =
                    valueReference.OriginatingFrame.DebuggerSession.Options.EvaluationOptions.Apply(options);

                // This can throw if there are members missing, which is entirely possible when debugging on a device,
                // due to stripping. It will throw EvaluatorException. Anything else is logged and thrown as a new
                // EvaluatorException. We can also get InvalidOperationException, but only if no other evaluators can
                // handle the current context, which is unlikely
                var displayString =
                    ExpressionEvaluators.EvaluateDisplayString(valueReference.OriginatingFrame, thisObj,
                                                               debuggerDisplayString, evaluationOptions, token);

                var flags = valueReference.DefaultFlags;
                if (valueReference is CalculatedValueReferenceDecorator <TValue> reference &&
                    !reference.AllowDefaultTypePresentation)
                {
                    flags |= ValueFlags.IsDefaultTypePresentation;
                }

                return(SimplePresentation.CreateSuccess(
                           ValuePresentationPart.Default(DisplayStringUtil.EscapeString(displayString)),
                           flags, instanceType, displayString));
            }
            catch (Exception ex)
            {
                // Log as warning, not error - there's nothing the user can do, and we're likely to encounter this with
                // device builds
                myLogger.Warn(ex,
                              comment: $"Unable to evaluate debugger display string for type {instanceType.GetGenericTypeDefinition().FullName}: {debuggerDisplayString}. " +
                              "Expected behaviour on devices due to stripping");
                return(null);
            }
        }