本文整理汇总了C#中Value.InvokeToString方法的典型用法代码示例。如果您正苦于以下问题:C# Value.InvokeToString方法的具体用法?C# Value.InvokeToString怎么用?C# Value.InvokeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Value
的用法示例。
在下文中一共展示了Value.InvokeToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePropertyFromValue
private static ObjectProperty CreatePropertyFromValue(string propertyName, Value value)
{
ObjectProperty property = new ObjectProperty();
property.Name = propertyName;
// property.Expression = ?.Age
// - cannot use expression,
// if the value is returned from an enumerator, it has no meaningful expression
property.IsAtomic = value.Type.IsPrimitive;
property.IsNull = value.IsNull;
property.Value = value.IsNull ? "" : value.InvokeToString();
return property;
}
示例2: FormatValue
public static string FormatValue(Thread evalThread, Value val)
{
if (val.IsNull) {
return "null";
} else if (val.Type.Kind == TypeKind.Array) {
StringBuilder sb = new StringBuilder();
sb.Append(new CSharpAmbience().ConvertType(val.Type));
sb.Append(" {");
bool first = true;
int size = val.ArrayLength;
for (int i = 0; i < size; i++) {
if (!first) sb.Append(", ");
first = false;
sb.Append(FormatValue(evalThread, val.GetElementAtPosition(i)));
}
sb.Append("}");
return sb.ToString();
} else if (val.Type.GetAllBaseTypeDefinitions().Any(def => def.IsKnownType(KnownTypeCode.ICollection))) {
StringBuilder sb = new StringBuilder();
sb.Append(new CSharpAmbience().ConvertType(val.Type));
sb.Append(" {");
val = val.GetPermanentReference(evalThread);
var countProp = val.Type.GetProperties(p => p.Name == "Count" && !p.IsExplicitInterfaceImplementation).Single();
int count = (int)val.GetMemberValue(evalThread, countProp).PrimitiveValue;
for(int i = 0; i < count; i++) {
if (i > 0) sb.Append(", ");
var itemProperty = val.Type.GetProperties(p => p.IsIndexer && p.Name == "Item" && !p.IsExplicitInterfaceImplementation).Single();
Value item = val.GetPropertyValue(evalThread, itemProperty, Eval.CreateValue(evalThread, i));
sb.Append(FormatValue(evalThread, item));
}
sb.Append("}");
return sb.ToString();
} else if (val.Type.IsKnownType(KnownTypeCode.String) || val.Type.IsPrimitiveType()) {
return TextWriterTokenWriter.PrintPrimitiveValue(val.PrimitiveValue);
} else {
return val.InvokeToString(evalThread);
}
}
示例3: ValueNode
/// <summary>
/// Constructor used by the factory method Create()
/// </summary>
/// <param name="val"></param>
/// <exception cref="System.Management.Automation.GetValueException">
/// Can be thrown by InvokeToString()
/// </exception>
public ValueNode(Value val)
{
this.expression = val.Expression;
canSetText = false;
if (val.Type.IsInteger) {
canSetText =
(val.Expression is LocalVariableIdentifierExpression) ||
(val.Expression is ParameterIdentifierExpression) ||
(val.Expression is ArrayIndexerExpression) ||
(val.Expression is MemberReferenceExpression && ((MemberReferenceExpression)val.Expression).MemberInfo is FieldInfo);
}
this.Image = IconService.GetBitmap("Icons.16x16." + GetImageName(val));
this.Name = val.Expression.CodeTail;
if (DebuggingOptions.Instance.ShowValuesInHexadecimal && val.Type.IsInteger) {
fullText = String.Format("0x{0:X}", val.PrimitiveValue);
} else if (val.Type.IsPointer) {
fullText = String.Format("0x{0:X}", val.PointerAddress);
} else {
fullText = val.AsString;
}
if (val.Type != null) {
this.Type = val.Type.Name;
} else {
this.Type = String.Empty;
}
// Note that these return enumerators so they are lazy-evaluated
this.ChildNodes = null;
if (val.IsNull) {
} else if (val.Type.IsClass || val.Type.IsValueType) {
this.ChildNodes = Utils.GetChildNodesOfObject(this.Expression, val.Type);
} else if (val.Type.IsArray) {
this.ChildNodes = Utils.GetChildNodesOfArray(this.Expression, val.ArrayDimensions);
} else if (val.Type.IsPointer) {
Value deRef = val.Dereference();
if (deRef != null) {
this.ChildNodes = new AbstractNode [] { new ValueNode(deRef) };
}
}
if (DebuggingOptions.Instance.ICorDebugVisualizerEnabled) {
AbstractNode info = ICorDebug.GetDebugInfoRoot(val.Process, val.CorValue);
this.ChildNodes = PrependNode(info, this.ChildNodes);
}
// Do last since it may expire the object
if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) {
fullText = val.InvokeToString();
}
this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText;
}