Skip to content

Commit 07b5250

Browse files
committed
Fixed DebugView proxy type or Slice and SliceWriter not evaluating in VS2015
- VS2015 does not want to evaluate the Data property because it call into native code (memmove) - replaced with naive buffer copying (only invoked at debug time when looking at the locals with a debugger, so no big deal)
1 parent 000c6c0 commit 07b5250

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

FoundationDB.Client/Utils/Slice.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ public string ToHexaString(char sep)
10371037
return sb.ToString();
10381038
}
10391039

1040-
private static StringBuilder EscapeString(StringBuilder sb, byte[] buffer, int offset, int count, Encoding encoding)
1040+
[NotNull]
1041+
private static StringBuilder EscapeString(StringBuilder sb, [NotNull] byte[] buffer, int offset, int count, [NotNull] Encoding encoding)
10411042
{
10421043
if (sb == null) sb = new StringBuilder(count + 16);
10431044
foreach(var c in encoding.GetChars(buffer, offset, count))
@@ -2404,6 +2405,7 @@ public bool Equals(byte[] other)
24042405

24052406
#endregion
24062407

2408+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
24072409
private sealed class DebugView
24082410
{
24092411
private readonly Slice m_slice;
@@ -2415,7 +2417,23 @@ public DebugView(Slice slice)
24152417

24162418
public byte[] Data
24172419
{
2418-
get { return m_slice.GetBytes(); }
2420+
get
2421+
{
2422+
if (m_slice.Count == 0) return m_slice.Array == null ? null : EmptyArray;
2423+
if (m_slice.Offset == 0 && m_slice.Count == m_slice.Array.Length) return m_slice.Array;
2424+
var tmp = new byte[m_slice.Count];
2425+
System.Array.Copy(m_slice.Array, m_slice.Offset, tmp, 0, m_slice.Count);
2426+
return tmp;
2427+
}
2428+
}
2429+
2430+
public string Text
2431+
{
2432+
get
2433+
{
2434+
if (m_slice.Count == 0) return m_slice.Array == null ? null : String.Empty;
2435+
return m_slice.ToAsciiOrHexaString();
2436+
}
24192437
}
24202438

24212439
public int Count

FoundationDB.Client/Utils/SliceWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ private static void FailCannotGrowBuffer()
846846
throw new OutOfMemoryException("Buffer cannot be resized, because it would exceed the maximum allowed size");
847847
}
848848

849+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
849850
private sealed class DebugView
850851
{
851852
private readonly SliceWriter m_writer;
@@ -860,7 +861,9 @@ public byte[] Data
860861
get
861862
{
862863
if (m_writer.Buffer.Length == m_writer.Position) return m_writer.Buffer;
863-
return m_writer.GetBytes();
864+
var tmp = new byte[m_writer.Position];
865+
System.Array.Copy(m_writer.Buffer, tmp, tmp.Length);
866+
return tmp;
864867
}
865868
}
866869

0 commit comments

Comments
 (0)