Skip to content

Commit 3d73709

Browse files
authored
Add GetFieldValue(Async)<T> support for XmlReader, TextReader, Stream (#1019)
1 parent 6ac1e49 commit 3d73709

File tree

9 files changed

+1123
-190
lines changed

9 files changed

+1123
-190
lines changed

doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml

+8-4
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@
319319
<summary>Synchronously gets the value of the specified column as a type. <see cref="M:Microsoft.Data.SqlClient.SqlDataReader.GetFieldValueAsync``1(System.Int32,System.Threading.CancellationToken)" /> is the asynchronous version of this method.</summary>
320320
<returns>The returned type object.</returns>
321321
<remarks>
322-
<format type="text/markdown"><![CDATA[
322+
<format type="text/markdown">
323+
<![CDATA[
323324
324325
## Remarks
325326
`T` can be one of the following types:
@@ -332,7 +333,8 @@
332333
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
333334
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
334335
|SqlInt64|SqlMoney|SqlSingle|SqlString|
335-
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
336+
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
337+
|XmlReader||||
336338
337339
For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).
338340
@@ -359,7 +361,8 @@
359361
<summary>Asynchronously gets the value of the specified column as a type. <see cref="M:Microsoft.Data.SqlClient.SqlDataReader.GetFieldValue``1(System.Int32)" /> is the synchronous version of this method.</summary>
360362
<returns>The returned type object.</returns>
361363
<remarks>
362-
<format type="text/markdown"><![CDATA[
364+
<format type="text/markdown">
365+
<![CDATA[
363366
364367
## Remarks
365368
`T` can be one of the following types:
@@ -372,7 +375,8 @@
372375
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
373376
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
374377
|SqlInt64|SqlMoney|SqlSingle|SqlString|
375-
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
378+
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
379+
|XmlReader||||
376380
377381
For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).
378382

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ internal SqlXml ToSqlXml()
133133
[MethodImpl(MethodImplOptions.NoInlining)]
134134
internal XmlReader ToXmlReader()
135135
{
136-
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false);
136+
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
137137
}
138138

139139
public bool IsNull

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs

+193-73
Large diffs are not rendered by default.

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

+2-23
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
using System.Data.SqlTypes;
88
using System.Diagnostics;
99
using System.IO;
10-
using System.Reflection;
1110
using System.Runtime.CompilerServices;
1211
using System.Xml;
12+
using Microsoft.Data.SqlTypes;
1313

1414
namespace Microsoft.Data.SqlClient
1515
{
@@ -134,26 +134,7 @@ internal SqlXml ToSqlXml()
134134
[MethodImpl(MethodImplOptions.NoInlining)]
135135
internal XmlReader ToXmlReader()
136136
{
137-
//XmlTextReader xr = new XmlTextReader(fragment, XmlNodeType.Element, null);
138-
XmlReaderSettings readerSettings = new XmlReaderSettings();
139-
readerSettings.ConformanceLevel = ConformanceLevel.Fragment;
140-
141-
// Call internal XmlReader.CreateSqlReader from System.Xml.
142-
// Signature: internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext);
143-
MethodInfo createSqlReaderMethodInfo = typeof(System.Xml.XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
144-
object[] args = new object[3] { ToStream(), readerSettings, null };
145-
XmlReader xr;
146-
147-
new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.MemberAccess).Assert();
148-
try
149-
{
150-
xr = (XmlReader)createSqlReaderMethodInfo.Invoke(null, args);
151-
}
152-
finally
153-
{
154-
System.Security.Permissions.ReflectionPermission.RevertAssert();
155-
}
156-
return xr;
137+
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
157138
}
158139

159140
public bool IsNull
@@ -163,7 +144,5 @@ public bool IsNull
163144
return (_cachedBytes == null) ? true : false;
164145
}
165146
}
166-
167147
}
168-
169148
}

0 commit comments

Comments
 (0)