Skip to content

Commit 9a7d53e

Browse files
authored
Move into shared for SqlCachedBuffer.cs (#1280)
1 parent 8476c8e commit 9a7d53e

File tree

4 files changed

+27
-175
lines changed

4 files changed

+27
-175
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@
205205
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs">
206206
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs</Link>
207207
</Compile>
208+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlCachedBuffer.cs">
209+
<Link>Microsoft\Data\SqlClient\SqlCachedBuffer.cs</Link>
210+
</Compile>
208211
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs">
209212
<Link>Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs</Link>
210213
</Compile>
@@ -499,7 +502,6 @@
499502
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
500503
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
501504
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs" />
502-
<Compile Include="Microsoft\Data\SqlClient\SqlCachedBuffer.cs" />
503505
<Compile Include="Microsoft\Data\SqlClient\SqlClientDiagnosticListenerExtensions.cs" />
504506
<Compile Include="Microsoft\Data\SqlClient\SqlClientFactory.cs" />
505507
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@
276276
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs">
277277
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs</Link>
278278
</Compile>
279+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlCachedBuffer.cs">
280+
<Link>Microsoft\Data\SqlClient\SqlCachedBuffer.cs</Link>
281+
</Compile>
279282
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs">
280283
<Link>Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs</Link>
281284
</Compile>
@@ -462,7 +465,6 @@
462465
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
463466
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
464467
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs" />
465-
<Compile Include="Microsoft\Data\SqlClient\SqlCachedBuffer.cs" />
466468
<Compile Include="Microsoft\Data\SqlClient\SqlCertificateCallbacks.cs" />
467469
<Compile Include="Microsoft\Data\SqlClient\SqlClientFactory.cs" />
468470
<Compile Include="Microsoft\Data\SqlClient\SqlClientOriginalAddressInfo.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
namespace Microsoft.Data.SqlClient
1414
{
1515
// Caches the bytes returned from partial length prefixed datatypes, like XML
16-
sealed internal class SqlCachedBuffer : System.Data.SqlTypes.INullable
16+
internal sealed class SqlCachedBuffer : INullable
1717
{
18-
public static readonly SqlCachedBuffer Null = new SqlCachedBuffer();
19-
private const int _maxChunkSize = 2048; // Arbitrary value for chunk size. Revisit this later for better perf
18+
public static readonly SqlCachedBuffer Null = new();
19+
private const int MaxChunkSize = 2048; // Arbitrary value for chunk size. Revisit this later for better perf
2020

21-
private List<byte[]> _cachedBytes;
21+
private readonly List<byte[]> _cachedBytes;
2222

2323
private SqlCachedBuffer()
2424
{
@@ -30,23 +30,20 @@ private SqlCachedBuffer(List<byte[]> cachedBytes)
3030
_cachedBytes = cachedBytes;
3131
}
3232

33-
internal List<byte[]> CachedBytes
34-
{
35-
get { return _cachedBytes; }
36-
}
33+
internal List<byte[]> CachedBytes =>_cachedBytes;
3734

38-
// Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
35+
/// <summary>
36+
/// Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
37+
/// </summary>
3938
internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
4039
{
41-
int cb = 0;
42-
ulong plplength;
4340
byte[] byteArr;
4441

45-
List<byte[]> cachedBytes = new List<byte[]>();
42+
List<byte[]> cachedBytes = new();
4643
buffer = null;
4744

4845
// the very first length is already read.
49-
if (!parser.TryPlpBytesLeft(stateObj, out plplength))
46+
if (!parser.TryPlpBytesLeft(stateObj, out ulong plplength))
5047
{
5148
return false;
5249
}
@@ -55,10 +52,12 @@ internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsPa
5552
do
5653
{
5754
if (plplength == 0)
55+
{
5856
break;
57+
}
5958
do
6059
{
61-
cb = (plplength > (ulong)_maxChunkSize) ? _maxChunkSize : (int)plplength;
60+
int cb = (plplength > (ulong)MaxChunkSize) ? MaxChunkSize : (int)plplength;
6261
byteArr = new byte[cb];
6362
if (!stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb))
6463
{
@@ -105,27 +104,32 @@ internal Stream ToStream()
105104
override public string ToString()
106105
{
107106
if (IsNull)
107+
{
108108
throw new SqlNullValueException();
109+
}
109110

110111
if (_cachedBytes.Count == 0)
111112
{
112113
return string.Empty;
113114
}
114-
SqlXml sxml = new SqlXml(ToStream());
115+
SqlXml sxml = new(ToStream());
115116
return sxml.Value;
116117
}
117118

118119
internal SqlString ToSqlString()
119120
{
120121
if (IsNull)
122+
{
121123
return SqlString.Null;
124+
}
125+
122126
string str = ToString();
123127
return new SqlString(str);
124128
}
125129

126130
internal SqlXml ToSqlXml()
127131
{
128-
SqlXml sx = new SqlXml(ToStream());
132+
SqlXml sx = new(ToStream());
129133
return sx;
130134
}
131135

@@ -136,14 +140,6 @@ internal XmlReader ToXmlReader()
136140
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
137141
}
138142

139-
public bool IsNull
140-
{
141-
get
142-
{
143-
return (_cachedBytes == null) ? true : false;
144-
}
145-
}
146-
147-
143+
public bool IsNull => _cachedBytes == null;
148144
}
149145
}

0 commit comments

Comments
 (0)