本文整理汇总了C#中Value.GetElementAtPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Value.GetElementAtPosition方法的具体用法?C# Value.GetElementAtPosition怎么用?C# Value.GetElementAtPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Value
的用法示例。
在下文中一共展示了Value.GetElementAtPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}