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 trimmer annotations to System.Data.Common #52046

Merged
merged 15 commits into from
Jun 11, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ public partial interface ITypeDescriptorContext : System.IServiceProvider
}
public partial interface ITypedList
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members of property types might be trimmed if not referenced directly")]
krwq marked this conversation as resolved.
Show resolved Hide resolved
krwq marked this conversation as resolved.
Show resolved Hide resolved
System.ComponentModel.PropertyDescriptorCollection GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors);
string GetListName(System.ComponentModel.PropertyDescriptor[] listAccessors);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace System.ComponentModel
{
public interface ITypedList
{
string GetListName(PropertyDescriptor[] listAccessors);

[RequiresUnreferencedCode("Members of property types might be trimmed if not referenced directly")]
PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors);
krwq marked this conversation as resolved.
Show resolved Hide resolved
}
}
472 changes: 294 additions & 178 deletions src/libraries/System.Data.Common/ref/System.Data.Common.cs

Large diffs are not rendered by default.

212 changes: 25 additions & 187 deletions src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Numerics;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -149,11 +150,13 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
return BigInteger.Parse(s, System.Globalization.CultureInfo.InvariantCulture);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
return ((BigInteger)value).ToString("D", System.Globalization.CultureInfo.InvariantCulture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -169,11 +170,13 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
return XmlConvert.ToBoolean(s);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
return XmlConvert.ToString((bool)value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -241,11 +242,13 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
return XmlConvert.ToByte(s);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
return XmlConvert.ToString((byte)value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -173,11 +174,13 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
return XmlConvert.ToChar(s);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
return XmlConvert.ToString((char)value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ public DbCommand GetInsertCommand(bool useColumnsForParameterNames)
{
return GetInsertCommand(null, useColumnsForParameterNames);
}

internal DbCommand GetInsertCommand(DataRow? dataRow, bool useColumnsForParameterNames)
{
BuildCache(true, dataRow, useColumnsForParameterNames);
Expand All @@ -1329,10 +1330,12 @@ public DbCommand GetUpdateCommand()
{
return GetUpdateCommand(null, false);
}

public DbCommand GetUpdateCommand(bool useColumnsForParameterNames)
{
return GetUpdateCommand(null, useColumnsForParameterNames);
}

internal DbCommand GetUpdateCommand(DataRow? dataRow, bool useColumnsForParameterNames)
{
BuildCache(true, dataRow, useColumnsForParameterNames);
Expand All @@ -1344,10 +1347,12 @@ public DbCommand GetDeleteCommand()
{
return GetDeleteCommand(null, false);
}

public DbCommand GetDeleteCommand(bool useColumnsForParameterNames)
{
return GetDeleteCommand(null, useColumnsForParameterNames);
}

internal DbCommand GetDeleteCommand(DataRow? dataRow, bool useColumnsForParameterNames)
{
BuildCache(true, dataRow, useColumnsForParameterNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace System.Data.Common
Expand All @@ -12,6 +13,8 @@ internal sealed class DbSchemaRow
private readonly DbSchemaTable _schemaTable;
private readonly DataRow _dataRow;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = "Filter expression is null.")]
krwq marked this conversation as resolved.
Show resolved Hide resolved
internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
{
DataColumn? sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ object ICloneable.Clone()
}

[EditorBrowsable(EditorBrowsableState.Advanced)]
public DataColumn? GetDataColumnBySchemaAction(DataTable dataTable, Type? dataType, MissingSchemaAction schemaAction)
public DataColumn? GetDataColumnBySchemaAction(DataTable dataTable, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? dataType, MissingSchemaAction schemaAction)
{
return GetDataColumnBySchemaAction(SourceColumn, DataSetColumn, dataTable, dataType, schemaAction);
}

[EditorBrowsable(EditorBrowsableState.Advanced)]
public static DataColumn? GetDataColumnBySchemaAction(string? sourceColumn, string? dataSetColumn, DataTable dataTable, Type? dataType, MissingSchemaAction schemaAction)
public static DataColumn? GetDataColumnBySchemaAction(string? sourceColumn, string? dataSetColumn, DataTable dataTable, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? dataType, MissingSchemaAction schemaAction)
{
if (null == dataTable)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ object ICloneable.Clone()
return CreateDataColumnBySchemaAction(sourceColumn, dataSetColumn, dataTable, dataType, schemaAction);
}

internal static DataColumn? CreateDataColumnBySchemaAction(string? sourceColumn, string? dataSetColumn, DataTable dataTable, Type? dataType, MissingSchemaAction schemaAction)
internal static DataColumn? CreateDataColumnBySchemaAction(string? sourceColumn, string? dataSetColumn, DataTable dataTable, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? dataType, MissingSchemaAction schemaAction)
{
Debug.Assert(dataTable != null, "Should not call with a null DataTable");
if (string.IsNullOrEmpty(dataSetColumn))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ internal void ValidateSourceColumn(int index, string? value)
}

[EditorBrowsable(EditorBrowsableState.Advanced)]
public static DataColumn? GetDataColumn(DataColumnMappingCollection? columnMappings, string sourceColumn, Type? dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
public static DataColumn? GetDataColumn(DataColumnMappingCollection? columnMappings, string sourceColumn, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
{
if (null != columnMappings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Xml;
using System.Xml.Serialization;

Expand Down Expand Up @@ -269,19 +270,25 @@ public virtual void SetCapacity(int capacity)
}
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public abstract object ConvertXmlToObject(string s);

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public virtual object ConvertXmlToObject(XmlReader xmlReader, XmlRootAttribute xmlAttrib)
{
return ConvertXmlToObject(xmlReader.Value);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public abstract string ConvertObjectToXml(object value);

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public virtual void ConvertObjectToXml(object value, XmlWriter xmlWriter, XmlRootAttribute? xmlAttrib)
{
xmlWriter.WriteString(ConvertObjectToXml(value)); // should it be NO OP?
}

public static DataStorage CreateStorage(DataColumn column, Type dataType, StorageType typeCode)
public static DataStorage CreateStorage(DataColumn column, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, StorageType typeCode)
{
Debug.Assert(typeCode == GetStorageType(dataType), "Incorrect storage type specified");
if ((StorageType.Empty == typeCode) && (null != dataType))
Expand Down Expand Up @@ -557,6 +564,7 @@ protected void SetNullStorage(BitArray nullbits)
/// Types like "System.Data.SqlTypes.SqlString" will load because they are in the same assembly as this code
/// Types like "System.Numerics.BigInteger" won't load because they are not special and not same assembly as this code
/// </remarks>
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
krwq marked this conversation as resolved.
Show resolved Hide resolved
internal static Type GetType(string value)
{
Type? dataType = Type.GetType(value); // throwOnError=false, ignoreCase=fase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object ICloneable.Clone()
}

[EditorBrowsable(EditorBrowsableState.Advanced)]
public DataColumn? GetDataColumn(string sourceColumn, Type? dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
public DataColumn? GetDataColumn(string sourceColumn, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction)
{
return DataColumnMappingCollection.GetDataColumn(_columnMappings, sourceColumn, dataType, dataTable, mappingAction, schemaAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Xml;
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -176,11 +177,13 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
return XmlConvert.ToDateTimeOffset(s);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
return XmlConvert.ToString((DateTimeOffset)value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Xml;
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace System.Data.Common
{
Expand Down Expand Up @@ -215,6 +216,7 @@ public override void SetCapacity(int capacity)
base.SetCapacity(capacity);
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override object ConvertXmlToObject(string s)
{
object retValue;
Expand All @@ -229,6 +231,7 @@ public override object ConvertXmlToObject(string s)
return retValue;
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
public override string ConvertObjectToXml(object value)
{
string retValue;
Expand Down
Loading