Add byte array to encoding extension

This commit is contained in:
Matt Nadareski
2023-09-15 00:23:03 -04:00
parent 9a93c7b15d
commit a35a9a4ab6
2 changed files with 17 additions and 4 deletions

View File

@@ -18,6 +18,19 @@ namespace BinaryObjectScanner.Printing
return sb.AppendLine($"{prefixString}: {valueString}");
}
/// <summary>
/// Append a line containing a UInt8[] value as a string to a StringBuilder
/// </summary>
#if NET48
public static StringBuilder AppendLine(this StringBuilder sb, byte[] value, string prefixString, Encoding encoding)
#else
public static StringBuilder AppendLine(this StringBuilder sb, byte[]? value, string prefixString, Encoding encoding)
#endif
{
string valueString = (value == null ? "[NULL]" : encoding.GetString(value).Replace("\0", string.Empty));
return sb.AppendLine($"{prefixString}: {valueString}");
}
/// <summary>
/// Append a line containing a Int16[] value to a StringBuilder
/// </summary>

View File

@@ -225,7 +225,7 @@ namespace BinaryObjectScanner.Printing
}
#endif
builder.AppendLine(typeAndNameString.Value.Length, " Length");
builder.AppendLine($" Text: {(typeAndNameString.Value.Text != null ? Encoding.ASCII.GetString(typeAndNameString.Value.Text).TrimEnd('\0') : "[EMPTY]")}");
builder.AppendLine(typeAndNameString.Value.Text, " Text", Encoding.ASCII);
}
}
builder.AppendLine();
@@ -257,7 +257,7 @@ namespace BinaryObjectScanner.Printing
}
builder.AppendLine(entry.Length, " Length");
builder.AppendLine($" Name string: {(entry.NameString != null ? Encoding.ASCII.GetString(entry.NameString).TrimEnd('\0') : "[EMPTY]")}");
builder.AppendLine(entry.NameString, " Name string", Encoding.ASCII);
builder.AppendLine(entry.OrdinalNumber, " Ordinal number");
}
builder.AppendLine();
@@ -324,7 +324,7 @@ namespace BinaryObjectScanner.Printing
}
#endif
builder.AppendLine(entry.Value.Length, " Length");
builder.AppendLine($" Name string: {(entry.Value.NameString != null ? Encoding.ASCII.GetString(entry.Value.NameString) : "[EMPTY]")}");
builder.AppendLine(entry.Value.NameString, " Name string", Encoding.ASCII);
}
builder.AppendLine();
}
@@ -399,7 +399,7 @@ namespace BinaryObjectScanner.Printing
}
builder.AppendLine(entry.Length, " Length");
builder.AppendLine($" Name string: {(entry.NameString != null ? Encoding.ASCII.GetString(entry.NameString) : "[EMPTY]")}");
builder.AppendLine(entry.NameString, " Name string", Encoding.ASCII);
builder.AppendLine(entry.OrdinalNumber, " Ordinal number");
}
builder.AppendLine();