1313namespace 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