Skip to content

Commit

Permalink
Fix bunch of annontations
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Mar 25, 2023
1 parent 82353f8 commit 2b2b4b8
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<DocumentationFile>$(OutputPath)\$(TargetFramework)\Microsoft.Data.SqlClient.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Product>Core $(BaseProduct)</Product>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<NoWarn>$(NoWarn);IL2026;IL2057;IL2067;IL2070;IL2072;IL2075;IL2077;IL2080;IL2093;IL2111</NoWarn>
<EnableTrimAnalyzer Condition="$(TargetFramework)=='net6.0'">true</EnableTrimAnalyzer>
<NoWarn>$(NoWarn);IL2026;IL2057;IL2072;IL2075</NoWarn>
</PropertyGroup>
<PropertyGroup>
<DebugType>portable</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Data.Common;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -438,6 +439,10 @@ internal void Bind(TdsParserStateObject stateObj)
_defaultLCID = _parser.DefaultLCID;
}

#if NET6_0_OR_GREATER
[SuppressMessage("ReflectionAnalysis", "IL2111",
Justification = "System.Type.TypeInitializer would not be used in dataType and providerSpecificDataType columns.")]
#endif
internal DataTable BuildSchemaTable()
{
_SqlMetaDataSet md = this.MetaData;
Expand Down Expand Up @@ -1232,6 +1237,11 @@ override public IEnumerator GetEnumerator()
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetFieldType/*' />
#if NET6_0_OR_GREATER
[SuppressMessage("ReflectionAnalysis", "IL2093:MismatchOnMethodReturnValueBetweenOverrides",
Justification = "Annotations for DbDataReader was not shipped in net6.0")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
override public Type GetFieldType(int i)
{
SqlStatistics statistics = null;
Expand All @@ -1248,6 +1258,9 @@ override public Type GetFieldType(int i)
}
}

#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
private Type GetFieldTypeInternal(_SqlMetaData metaData)
{
Type fieldType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Data.Common;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Security;
using System.Security.Authentication;
Expand Down Expand Up @@ -564,6 +565,9 @@ public void CopyFrom(SqlMetaDataXmlSchemaCollection original)

sealed internal class SqlMetaDataUdt
{
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
#endif
internal Type Type;
internal string DatabaseName;
internal string SchemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -154,7 +155,11 @@ private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string config
return null;
}

private static object CreateInstance(Type type, string retryMethodName, SqlRetryLogicOption option)
private static object CreateInstance(
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicMethods)]
#endif
Type type, string retryMethodName, SqlRetryLogicOption option)
{
string methodName = nameof(CreateInstance);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace Microsoft.Data.SqlClient.Server
Expand Down Expand Up @@ -228,6 +229,9 @@ internal SmiMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType
)
: this(
Expand All @@ -253,6 +257,9 @@ internal SmiMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool isMultiValued,
IList<SmiExtendedMetaData> fieldTypes,
Expand Down Expand Up @@ -282,6 +289,9 @@ internal SmiMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string udtAssemblyQualifiedName,
bool isMultiValued,
Expand Down Expand Up @@ -759,6 +769,9 @@ internal SmiExtendedMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string name,
string typeSpecificNamePart1,
Expand Down Expand Up @@ -792,6 +805,9 @@ internal SmiExtendedMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool isMultiValued,
IList<SmiExtendedMetaData> fieldMetaData,
Expand Down Expand Up @@ -829,6 +845,9 @@ internal SmiExtendedMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string udtAssemblyQualifiedName,
bool isMultiValued,
Expand Down Expand Up @@ -903,6 +922,9 @@ internal SmiParameterMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool isMultiValued,
IList<SmiExtendedMetaData> fieldMetaData,
Expand Down Expand Up @@ -942,6 +964,9 @@ internal SmiParameterMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string udtAssemblyQualifiedName,
bool isMultiValued,
Expand Down Expand Up @@ -1020,6 +1045,9 @@ internal SmiStorageMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string name,
string typeSpecificNamePart1,
Expand Down Expand Up @@ -1069,6 +1097,9 @@ internal SmiStorageMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool isMultiValued,
IList<SmiExtendedMetaData> fieldMetaData,
Expand Down Expand Up @@ -1123,6 +1154,9 @@ internal SmiStorageMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string udtAssemblyQualifiedName,
bool isMultiValued,
Expand Down Expand Up @@ -1233,6 +1267,9 @@ internal SmiQueryMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string name,
string typeSpecificNamePart1,
Expand Down Expand Up @@ -1290,6 +1327,9 @@ internal SmiQueryMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool isMultiValued,
IList<SmiExtendedMetaData> fieldMetaData,
Expand Down Expand Up @@ -1352,6 +1392,9 @@ internal SmiQueryMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string udtAssemblyQualifiedName,
bool isMultiValued,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Data.Common;
using Microsoft.Data.ProviderBase;

Expand Down Expand Up @@ -51,6 +52,9 @@ public virtual string GetDataTypeName(int ordinal)
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetFieldType/*' />
#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
public virtual Type GetFieldType(int ordinal) => GetFieldTypeFrameworkSpecific(ordinal);

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetValue/*' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Data.Common;

namespace Microsoft.Data.SqlClient.Server
{
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SqlDataRecord/*' />
public partial class SqlDataRecord : IDataRecord
{
{
#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
private Type GetFieldTypeFrameworkSpecific(int ordinal)
=> MetaType.GetMetaTypeFromSqlDbType(GetSqlMetaData(ordinal).SqlDbType, false).ClassType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Globalization;
using System.Data.SqlTypes;
using Microsoft.Data.Common;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Data.SqlClient.Server
{
Expand Down Expand Up @@ -237,14 +238,22 @@ int sortOrdinal

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlMetaData.xml' path='docs/members[@name="SqlMetaData"]/ctorNameDbTypeUserDefinedType/*' />
// udt ctor without tvp extended properties
public SqlMetaData(string name, SqlDbType dbType, Type userDefinedType)
public SqlMetaData(string name, SqlDbType dbType,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType)
{
Construct(name, dbType, userDefinedType, null, DefaultUseServerDefault, DefaultIsUniqueKey, DefaultColumnSortOrder, DefaultSortOrdinal);
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlMetaData.xml' path='docs/members[@name="SqlMetaData"]/ctorNameDbTypeUserDefinedTypeServerTypeName/*' />
// udt ctor without tvp extended properties
public SqlMetaData(string name, SqlDbType dbType, Type userDefinedType, string serverTypeName)
public SqlMetaData(string name, SqlDbType dbType,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType, string serverTypeName)
{
Construct(name, dbType, userDefinedType, serverTypeName, DefaultUseServerDefault, DefaultIsUniqueKey, DefaultColumnSortOrder, DefaultSortOrdinal);
}
Expand All @@ -253,7 +262,10 @@ public SqlMetaData(string name, SqlDbType dbType, Type userDefinedType, string s
// udt ctor
public SqlMetaData(
string name,
SqlDbType dbType,
SqlDbType dbType,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string serverTypeName,
bool useServerDefault,
Expand Down Expand Up @@ -345,6 +357,9 @@ public SqlMetaData(
byte scale,
long locale,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType
) : this(
name,
Expand Down Expand Up @@ -373,6 +388,9 @@ public SqlMetaData(
byte scale,
long localeId,
SqlCompareOptions compareOptions,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
bool useServerDefault,
bool isUniqueKey,
Expand Down Expand Up @@ -874,7 +892,10 @@ int sortOrdinal
// Construction for Udt type
private void Construct(
string name,
SqlDbType dbType,
SqlDbType dbType,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
#endif
Type userDefinedType,
string serverTypeName,
bool useServerDefault,
Expand Down
Loading

0 comments on commit 2b2b4b8

Please sign in to comment.