public VSCodeObjectSource(VSCodeDebuggerSession vsCodeDebuggerSession, int variablesReference, int parentVariablesReference, string name, string type, string evalName, int frameId, string val)
        {
            this.vsCodeDebuggerSession    = vsCodeDebuggerSession;
            this.parentVariablesReference = parentVariablesReference;
            this.variablesReference       = variablesReference;
            this.evalName = evalName;
            this.frameId  = frameId;

            if (type == null)
            {
                if (IsCSError(118, "is a namespace but is used like a variable", val, out string ns))
                {
                    this.display = this.name = this.val = ns;
                    this.flags   = ObjectValueFlags.Namespace;
                    this.type    = "<namespace>";
                    return;
                }

                if (IsCSError(119, "is a type, which is not valid in the given context", val, out string vtype))
                {
                    if (name.StartsWith("global::", StringComparison.Ordinal))
                    {
                        vtype = name.Substring("global::".Length);
                    }

                    this.display = this.name = this.val = ObjectValueAdaptor.GetCSharpTypeName(vtype);
                    this.flags   = ObjectValueFlags.Type;
                    this.type    = "<type>";
                    return;
                }
            }

            var actualType = GetActualTypeName(type);

            this.flags = parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly;
            this.type  = actualType.Replace(", ", ",");
            this.name  = GetFixedVariableName(name);

            if (actualType != "void")
            {
                this.val = GetFixedValue(val, this.type, actualType);
            }
            else
            {
                this.val = "No return value.";
            }
            this.display = val;

            if (this.name[0] == '[')
            {
                flags |= ObjectValueFlags.ArrayElement;
            }

            if (type == null || val == $"'{this.name}' threw an exception of type '{this.type}'")
            {
                flags |= ObjectValueFlags.Error;
            }
        }
Beispiel #2
0
        public VSCodeEvaluationSource(VSCodeDebuggerSession session, string expression, EvaluateResponse response, int frameId)  : base(session, 0, frameId)
        {
            this.expression = expression;
            this.response   = response;

            // FIXME: can we use PresentationHint.Attributes == VariablePresentationHint.AttributesValue.FailedEvaluation instead?
            if (response.Type == null)
            {
                if (IsCSError(118, "is a namespace but is used like a variable", response.Result, out string ns))
                {
                    Flags   = ObjectValueFlags.Namespace;
                    display = name = value = ns;
                    type    = "<namespace>";
                    return;
                }

                if (IsCSError(119, "is a type, which is not valid in the given context", response.Result, out string vtype))
                {
                    if (expression.StartsWith("global::", StringComparison.Ordinal))
                    {
                        vtype = expression.Substring("global::".Length);
                    }

                    display = name = value = ObjectValueAdaptor.GetCSharpTypeName(vtype);
                    Flags   = ObjectValueFlags.Type;
                    type    = "<type>";
                    return;
                }
            }

            var actualType = GetActualTypeName(response.Type);

            Flags = GetFlags(response.PresentationHint);
            type  = actualType.Replace(", ", ",");
            name  = expression;

            if (actualType != "void")
            {
                value = GetFixedValue(response.Result, type, actualType);
            }
            else
            {
                value = "No return value.";
            }
            display = response.Result;

            if (name[0] == '[')
            {
                Flags |= ObjectValueFlags.ArrayElement;
            }

            if (type == null || value == $"'{name}' threw an exception of type '{type}'")
            {
                Flags = ObjectValueFlags.Error;
            }
        }