本文整理汇总了C#中Debugger.Value.GetArrayElements方法的典型用法代码示例。如果您正苦于以下问题:C# Value.GetArrayElements方法的具体用法?C# Value.GetArrayElements怎么用?C# Value.GetArrayElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Debugger.Value
的用法示例。
在下文中一共展示了Value.GetArrayElements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatValue
public static string FormatValue(Value val)
{
if (val == null) {
return null;
} if (val.IsNull) {
return "null";
} else if (val.Type.IsArray) {
StringBuilder sb = new StringBuilder();
sb.Append(val.Type.Name);
sb.Append(" {");
bool first = true;
foreach(Value item in val.GetArrayElements()) {
if (!first) sb.Append(", ");
first = false;
sb.Append(FormatValue(item));
}
sb.Append("}");
return sb.ToString();
} else if (val.Type.GetInterface(typeof(ICollection).FullName) != null) {
StringBuilder sb = new StringBuilder();
sb.Append(val.Type.Name);
sb.Append(" {");
val = val.GetPermanentReference();
int count = (int)val.GetMemberValue("Count").PrimitiveValue;
for(int i = 0; i < count; i++) {
if (i > 0) sb.Append(", ");
DebugPropertyInfo itemProperty = (DebugPropertyInfo)val.Type.GetProperty("Item");
Value item = val.GetPropertyValue(itemProperty, Eval.CreateValue(val.AppDomain, i));
sb.Append(FormatValue(item));
}
sb.Append("}");
return sb.ToString();
} else if (val.Type.FullName == typeof(char).FullName) {
return "'" + val.PrimitiveValue.ToString() + "'";
} else if (val.Type.FullName == typeof(string).FullName) {
return "\"" + val.PrimitiveValue.ToString() + "\"";
} else if (val.Type.IsPrimitive) {
return val.PrimitiveValue.ToString();
} else {
return val.InvokeToString();
}
}
示例2: MakeValueView
/// <summary>
/// Возвращает текстовое представление для значения val
/// </summary>
public string MakeValueView(Value val)
{
bool by_ref = false;
if ((val.Type.IsByRef() && !val.Type.IsPrimitive))
{
by_ref = true;
val = val.Dereference;
}
int v = 0;
NamedValue nv = GetNullBasedArray(val);//mozhet eto massiv
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (nv != null)//staticheskij massiv
{
sb.Append('(');
NamedValueCollection nvc = nv.GetArrayElements();
for (int i = 0; i < nvc.Count; i++)
{
if (i > 10)
{
sb.Append("...");
break;
}
sb.Append(MakeValueView(nvc[i]));
if (i < nvc.Count - 1) sb.Append(',');
}
sb.Append(')');
//sb.AppendLine();
//sb.Remove(
}
else if (val.IsPrimitive)
{
if (val.Type.ManagedType == typeof(string) || val.Type.ManagedType == typeof(char))
sb.Append("'" + val.AsString + "'");
else
sb.Append(val.AsString);
}
else if (val.IsNull)
{
sb.Append("nil");
}
else if (DebugUtils.IsEnum(val, out v))
{
sb.Append(ValueItem.MakeEnumText(val));
}
else if (val.Type.IsValueType && val.Type.GetMembers().Count <= 7)
{
sb.Append('{');
NamedValueCollection nvc = val.GetMembers();
for (int i = 0; i < nvc.Count; i++)
{
sb.Append(nvc[i].Name + ": " + MakeValueView(nvc[i]));
if (i < nvc.Count - 1) sb.Append("; ");
}
sb.Append('}');
}
else if (val.IsArray)//dinamicheskij massiv
{
NamedValueCollection nvc = val.GetArrayElements();
sb.Append('(');
for (int i = 0; i < nvc.Count; i++)
{
if (i > 10)
{
sb.Append("...");
break;
}
sb.Append(MakeValueView(nvc[i]));
if (i < nvc.Count - 1) sb.Append(',');
}
sb.Append(')');
//sb.AppendLine();
}
else if (val.IsObject)
{
if (val.Type.FullName == "PABCSystem.TypedSet")
sb.Append((val.Type.GetMember("ToString", BindingFlags.All)[0] as MethodInfo).Invoke(val, new Value[0] { }).AsString);
else
if (!val.Type.IsPrimitive)
{
if (DebugUtils.CheckForCollection(val.Type))
return DebugUtils.MakeViewForCollection(val);//esli eto kollekcija, to vyvodim ee po osobomu
bool is_failed = false;
string s = ExpressionEvaluator.GetToString(val, out is_failed);
if (s != null) return s;
else return val.AsString;
}
else
return val.AsString;
}
else return val.AsString;
return sb.ToString();
}