/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace dnSpy.Contracts.Debugger.Evaluation {
///
/// Format specifiers used by variables windows
///
/// https://docs.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-csharp
///
public static class PredefinedFormatSpecifiers {
///
/// Use decimal
///
public const string Decimal = "d";
///
/// Use hexadecimal
///
public const string Hexadecimal = "h";
///
/// No quotes, just show the raw string
///
public const string NoQuotes = "nq";
///
/// Raw view only
///
public const string RawView = "raw";
///
/// Results view only
///
public const string ResultsView = "results";
///
/// Dynamic view only
///
public const string DynamicView = "dynamic";
///
/// Show all members, even non-public ones
///
public const string ShowAllMembers = "hidden";
///
/// Emulate the code without real func-eval
///
public const string Emulator = "emulator";
///
/// No side effects, it implies
///
public const string NoSideEffects = "nse";
///
/// Allow func-eval even if is used and expression causes side effects
/// (ac = always calculate)
///
public const string AllowFuncEval = "ac";
// The following are dnSpy extensions
///
/// Digit separators
///
public const string DigitSeparators = "ds";
///
/// No digit seaparators
///
public const string NoDigitSeparators = "nds";
///
/// Use the same expression that's shown in the edit text box
///
public const string EditExpression = "edit";
///
/// Use ToString() if available to format the value
///
public new const string ToString = "ts";
///
/// Don't use ToString() to format the value
///
public const string NoToString = "nts";
///
/// Use if available
///
public const string DebuggerDisplay = "dda";
///
/// Don't use
///
public const string NoDebuggerDisplay = "ndda";
///
/// Show the full string value even if it's a very long string
///
public const string FullString = "fs";
///
/// Don't show the full string value if it's a very long string
///
public const string NoFullString = "nfs";
///
/// Show namespaces
///
public const string Namespaces = "ns";
///
/// Don't show namespaces
///
public const string NoNamespaces = "nns";
///
/// Show intrinsic type keywords (eg. int instead of Int32)
///
public const string Intrinsics = "intrinsics";
///
/// Don't show intrinsic type keywords (eg. int instead of Int32)
///
public const string NoIntrinsics = "nointrinsics";
///
/// Show tokens
///
public const string Tokens = "tokens";
///
/// Don't show tokens
///
public const string NoTokens = "notokens";
///
/// Show compiler generated members
///
public const string ShowCompilerGeneratedMembers = "cgm";
///
/// Don't show compiler generated members
///
public const string NoShowCompilerGeneratedMembers = "ncgm";
///
/// Respect attributes that can hide a member, eg. and
///
public const string RespectHideMemberAttributes = "hma";
///
/// Don't respect attributes that can hide a member, eg. and
///
public const string NoRespectHideMemberAttributes = "nhma";
///
/// Gets value formatter options
///
/// Format specifiers or null
/// Default options
///
public static DbgValueFormatterOptions GetValueFormatterOptions(ReadOnlyCollection? formatSpecifiers, DbgValueFormatterOptions options) {
if (formatSpecifiers is not null) {
for (int i = 0; i < formatSpecifiers.Count; i++) {
switch (formatSpecifiers[i]) {
case Decimal:
options |= DbgValueFormatterOptions.Decimal;
break;
case Hexadecimal:
options &= ~DbgValueFormatterOptions.Decimal;
break;
case NoQuotes:
options |= DbgValueFormatterOptions.NoStringQuotes;
break;
case DigitSeparators:
options |= DbgValueFormatterOptions.DigitSeparators;
break;
case NoDigitSeparators:
options &= ~DbgValueFormatterOptions.DigitSeparators;
break;
case EditExpression:
options |= DbgValueFormatterOptions.Edit;
break;
case ToString:
options |= DbgValueFormatterOptions.ToString;
break;
case NoToString:
options &= ~DbgValueFormatterOptions.ToString;
break;
case DebuggerDisplay:
options &= ~DbgValueFormatterOptions.NoDebuggerDisplay;
break;
case NoDebuggerDisplay:
options |= DbgValueFormatterOptions.NoDebuggerDisplay;
break;
case FullString:
options |= DbgValueFormatterOptions.FullString;
break;
case NoFullString:
options &= ~DbgValueFormatterOptions.FullString;
break;
case Namespaces:
options |= DbgValueFormatterOptions.Namespaces;
break;
case NoNamespaces:
options &= ~DbgValueFormatterOptions.Namespaces;
break;
case Intrinsics:
options |= DbgValueFormatterOptions.IntrinsicTypeKeywords;
break;
case NoIntrinsics:
options &= ~DbgValueFormatterOptions.IntrinsicTypeKeywords;
break;
case Tokens:
options |= DbgValueFormatterOptions.Tokens;
break;
case NoTokens:
options &= ~DbgValueFormatterOptions.Tokens;
break;
}
}
}
return options;
}
///
/// Gets value formatter type options
///
/// Format specifiers or null
/// Default options
///
public static DbgValueFormatterTypeOptions GetValueFormatterTypeOptions(ReadOnlyCollection? formatSpecifiers, DbgValueFormatterTypeOptions options) {
if (formatSpecifiers is not null) {
for (int i = 0; i < formatSpecifiers.Count; i++) {
switch (formatSpecifiers[i]) {
case Decimal:
options |= DbgValueFormatterTypeOptions.Decimal;
break;
case Hexadecimal:
options &= ~DbgValueFormatterTypeOptions.Decimal;
break;
case DigitSeparators:
options |= DbgValueFormatterTypeOptions.DigitSeparators;
break;
case NoDigitSeparators:
options &= ~DbgValueFormatterTypeOptions.DigitSeparators;
break;
case Namespaces:
options |= DbgValueFormatterTypeOptions.Namespaces;
break;
case NoNamespaces:
options &= ~DbgValueFormatterTypeOptions.Namespaces;
break;
case Intrinsics:
options |= DbgValueFormatterTypeOptions.IntrinsicTypeKeywords;
break;
case NoIntrinsics:
options &= ~DbgValueFormatterTypeOptions.IntrinsicTypeKeywords;
break;
case Tokens:
options |= DbgValueFormatterTypeOptions.Tokens;
break;
case NoTokens:
options &= ~DbgValueFormatterTypeOptions.Tokens;
break;
}
}
}
return options;
}
///
/// Gets value node evaluation options
///
/// Format specifiers or null
/// Default options
///
public static DbgValueNodeEvaluationOptions GetValueNodeEvaluationOptions(ReadOnlyCollection? formatSpecifiers, DbgValueNodeEvaluationOptions options) {
if (formatSpecifiers is not null) {
for (int i = 0; i < formatSpecifiers.Count; i++) {
switch (formatSpecifiers[i]) {
case DynamicView:
options |= DbgValueNodeEvaluationOptions.DynamicView;
break;
case ResultsView:
options |= DbgValueNodeEvaluationOptions.ResultsView;
break;
case RawView:
options |= DbgValueNodeEvaluationOptions.RawView;
break;
case ShowAllMembers:
options &= ~DbgValueNodeEvaluationOptions.PublicMembers;
break;
case ShowCompilerGeneratedMembers:
options &= ~DbgValueNodeEvaluationOptions.HideCompilerGeneratedMembers;
break;
case NoShowCompilerGeneratedMembers:
options |= DbgValueNodeEvaluationOptions.HideCompilerGeneratedMembers;
break;
case RespectHideMemberAttributes:
options |= DbgValueNodeEvaluationOptions.RespectHideMemberAttributes;
break;
case NoRespectHideMemberAttributes:
options &= ~DbgValueNodeEvaluationOptions.RespectHideMemberAttributes;
break;
}
}
}
return options;
}
}
}