Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetFieldValue(Async)<T> support for XmlReader, TextReader, Stream #1019

Merged
merged 13 commits into from
Oct 6, 2021
Merged
12 changes: 8 additions & 4 deletions doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@
<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>
<returns>The returned type object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
<format type="text/markdown">
<![CDATA[

## Remarks
`T` can be one of the following types:
Expand All @@ -332,7 +333,8 @@
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
|SqlInt64|SqlMoney|SqlSingle|SqlString|
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
|XmlReader||||

For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).

Expand All @@ -359,7 +361,8 @@
<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>
<returns>The returned type object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
<format type="text/markdown">
<![CDATA[

## Remarks
`T` can be one of the following types:
Expand All @@ -372,7 +375,8 @@
|SqlBoolean|SqlByte|SqlDateTime|SqlDecimal|
|SqlDouble|SqlGuid|SqlInt16|SqlInt32|
|SqlInt64|SqlMoney|SqlSingle|SqlString|
|String|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|||
|Stream|String|TextReader|UDT, which can be any CLR type marked with <xref:Microsoft.Data.SqlClient.Server.SqlUserDefinedTypeAttribute>.|
|XmlReader||||

For more information, see [SqlClient Streaming Support](/sql/connect/ado-net/sqlclient-streaming-support).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal SqlXml ToSqlXml()
[MethodImpl(MethodImplOptions.NoInlining)]
internal XmlReader ToXmlReader()
{
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false);
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
}

public bool IsNull
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Reflection;
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
using System.Runtime.CompilerServices;
using System.Xml;
using Microsoft.Data.SqlTypes;

namespace Microsoft.Data.SqlClient
{
Expand Down Expand Up @@ -134,26 +135,7 @@ internal SqlXml ToSqlXml()
[MethodImpl(MethodImplOptions.NoInlining)]
internal XmlReader ToXmlReader()
{
//XmlTextReader xr = new XmlTextReader(fragment, XmlNodeType.Element, null);
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ConformanceLevel = ConformanceLevel.Fragment;

// Call internal XmlReader.CreateSqlReader from System.Xml.
// Signature: internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext);
MethodInfo createSqlReaderMethodInfo = typeof(System.Xml.XmlReader).GetMethod("CreateSqlReader", BindingFlags.Static | BindingFlags.NonPublic);
object[] args = new object[3] { ToStream(), readerSettings, null };
XmlReader xr;

new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.MemberAccess).Assert();
try
{
xr = (XmlReader)createSqlReaderMethodInfo.Invoke(null, args);
}
finally
{
System.Security.Permissions.ReflectionPermission.RevertAssert();
}
return xr;
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false, async: false);
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
}

public bool IsNull
Expand Down
Loading