本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder.ConvertConstantValue方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSystemAstBuilder.ConvertConstantValue方法的具体用法?C# TypeSystemAstBuilder.ConvertConstantValue怎么用?C# TypeSystemAstBuilder.ConvertConstantValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder
的用法示例。
在下文中一共展示了TypeSystemAstBuilder.ConvertConstantValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValueAndUpdateUI
/// <summary> Get the value of the node and update the UI text fields. </summary>
/// <remarks> This should be only called once so the Value is not cached. </remarks>
void GetValueAndUpdateUI()
{
try {
Stopwatch watch = new Stopwatch();
watch.Start();
// Do not keep permanent reference
Value val = this.getValue();
if (val == null) {
Value = string.Empty;
Type = string.Empty;
GetChildren = null;
VisualizerCommands = null;
return;
}
// Note that the child collections are lazy-evaluated
if (val.IsNull) {
this.GetChildren = null;
} else if (val.Type.IsPrimitiveType() || val.Type.IsKnownType(KnownTypeCode.String)) { // Must be before IsClass
this.GetChildren = null;
} else if (val.Type.Kind == TypeKind.Array) { // Must be before IsClass
var dimBase = val.ArrayBaseIndicies; // Eval now
var dimSize = val.ArrayDimensions; // Eval now
if (val.ArrayLength > 0) {
this.GetChildren = () => GetArrayChildren(dimBase, dimSize);
}
} else if (val.Type.Kind == TypeKind.Class || val.Type.Kind == TypeKind.Struct) {
if (val.Type.IsKnownType(typeof(List<>))) {
if ((int)val.GetFieldValue("_size").PrimitiveValue > 0)
this.GetChildren = () => GetIListChildren(this.GetValue);
} else {
this.GetChildren = () => GetObjectChildren(val.Type);
}
} else if (val.Type.Kind == TypeKind.Pointer) {
if (val.Dereference() != null) {
this.GetChildren = () => new[] { new ValueNode(ClassBrowserIconService.LocalVariable, "*" + this.Name, () => GetValue().Dereference()) };
}
}
// Do last since it may expire the object
if (val.IsNull) {
fullValue = "null";
} else if (val.Type.IsInteger()) {
var i = val.PrimitiveValue;
if (DebuggingOptions.Instance.ShowIntegersAs == ShowIntegersAs.Decimal) {
fullValue = i.ToString();
} else {
string hex = string.Format("0x{0:X4}", i);
if (hex.Length > 6 ) hex = string.Format("0x{0:X8}", i);
if (hex.Length > 10) hex = string.Format("0x{0:X16}", i);
if (DebuggingOptions.Instance.ShowIntegersAs == ShowIntegersAs.Hexadecimal) {
fullValue = hex;
} else {
fullValue = string.Format("{0} ({1})", i, hex);
}
}
} else if (val.Type.Kind == TypeKind.Pointer) {
fullValue = String.Format("0x{0:X}", val.PointerAddress);
} else if (val.Type.IsKnownType(KnownTypeCode.String)) {
fullValue = '"' + val.InvokeToString(WindowsDebugger.EvalThread).Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r").Replace("\0", "\\0").Replace("\b", "\\b").Replace("\a", "\\a").Replace("\f", "\\f").Replace("\v", "\\v").Replace("\"", "\\\"") + '"';
} else if (val.Type.IsKnownType(KnownTypeCode.Char)) {
fullValue = "'" + val.InvokeToString(WindowsDebugger.EvalThread).Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r").Replace("\0", "\\0").Replace("\b", "\\b").Replace("\a", "\\a").Replace("\f", "\\f").Replace("\v", "\\v").Replace("\"", "\\\"") + "'";
} else if ((val.Type.Kind == TypeKind.Class || val.Type.Kind == TypeKind.Struct)) {
fullValue = val.FormatByDebuggerDisplayAttribute(WindowsDebugger.EvalThread);
if (fullValue == null)
fullValue = val.InvokeToString(WindowsDebugger.EvalThread);
} else if (val.Type.Kind == TypeKind.Enum) {
var primitiveValue = val.PrimitiveValue;
var builder = new TypeSystemAstBuilder();
builder.AlwaysUseShortTypeNames = true;
AstNode node = builder.ConvertConstantValue(val.Type, primitiveValue);
fullValue = node + "=" + primitiveValue;
} else {
fullValue = val.AsString();
}
this.error = null;
this.Value = (fullValue.Length > 256) ? fullValue.Substring(0, 256) + "..." : fullValue;
this.Type = val.Type.Name;
if (!val.IsNull) {
this.VisualizerCommands = VisualizerDescriptors.GetAllDescriptors()
.Where(descriptor => descriptor.IsVisualizerAvailable(val.Type))
.Select(descriptor => descriptor.CreateVisualizerCommand(this.Name, this.GetValue))
.ToList();
}
LoggingService.InfoFormatted("Evaluated node '{0}' in {1} ms", this.Name, watch.ElapsedMilliseconds);
} catch (GetValueException e) {
error = e;
this.Value = e.Message;
this.Type = string.Empty;
this.GetChildren = null;
this.VisualizerCommands = null;
} finally {
//.........这里部分代码省略.........
示例2: GetValue
string GetValue(ResolveResult value)
{
var astBuilder = new TypeSystemAstBuilder();
Expression ast = astBuilder.ConvertConstantValue(value);
return ast.ToString();
}