Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dapper/DefaultTypeMap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -33,6 +34,7 @@ internal static MethodInfo GetPropertySetterOrThrow(PropertyInfo propertyInfo, T

static MethodInfo Throw(PropertyInfo propertyInfo) => throw new InvalidOperationException("Property setting not found for: " + propertyInfo?.Name);
}
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "The property was obtained from the mapped type and its setter must be preserved whenever the property is preserved.")]
internal static MethodInfo? GetPropertySetter(PropertyInfo propertyInfo, Type type)
{
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
Expand All @@ -46,6 +48,7 @@ internal static MethodInfo GetPropertySetterOrThrow(PropertyInfo propertyInfo, T
null)!.GetSetMethod(true);
}

[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Dapper's runtime mapping contract requires the mapped type's properties to be preserved.")]
internal static List<PropertyInfo> GetSettableProps(Type t)
{
return t
Expand All @@ -54,6 +57,7 @@ internal static List<PropertyInfo> GetSettableProps(Type t)
.ToList();
}

[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Dapper's runtime mapping contract requires the mapped type's fields to be preserved.")]
private static FieldInfo[] GetSettableFields(Type t)
{
return t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Expand Down
8 changes: 8 additions & 0 deletions Dapper/NRT.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#if !NET5_0_OR_GREATER
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
internal sealed class UnconditionalSuppressMessageAttribute : Attribute
{
public UnconditionalSuppressMessageAttribute(string category, string checkId) { }

public string? Justification { get; set; }
}

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
Expand Down
3 changes: 3 additions & 0 deletions Dapper/SqlDataRecordListTVPParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
Expand Down Expand Up @@ -64,6 +65,8 @@ private static Action<IDbDataParameter, string> GetUDT(Type type)
}
}

[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "The provider parameter type is only known at runtime and must preserve its public properties.")]
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This fallback is only used for provider-specific structured parameters and is not supported by Dapper's AOT interceptors.")]
static Action<IDbDataParameter, string?> CreateFor(Type type, string nameProperty, int sqlDbType)
{
var name = type.GetProperty(nameProperty, BindingFlags.Public | BindingFlags.Instance);
Expand Down
4 changes: 4 additions & 0 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler? handler, bool clo
AddTypeHandlerCore(type, handler, true); // do not allow suppress clone
}

[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "Runtime type-handler registration requires the caller to statically root the corresponding TypeHandlerCache<T> instantiation.")]
private static void AddTypeHandlerCore(Type type, ITypeHandler? handler, bool clone)
{
if (type is null) throw new ArgumentNullException(nameof(type));
Expand Down Expand Up @@ -458,6 +459,7 @@ public static void SetDbType(IDataParameter parameter, object value)
[Obsolete(ObsoleteInternalUsageOnly, false)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "Runtime generic construction is limited to the optional SQL data-record handler path, which is not supported by Dapper's AOT interceptors.")]
public static DbType? LookupDbType(Type type, string name, bool demand, out ITypeHandler? handler)
{
handler = null;
Expand Down Expand Up @@ -2554,6 +2556,8 @@ private static bool IsValueTuple(Type? type) => (type?.IsValueType == true
&& type.FullName?.StartsWith("System.ValueTuple`", StringComparison.Ordinal) == true)
|| (type is not null && IsValueTuple(Nullable.GetUnderlyingType(type)));

[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "The runtime parameter generator requires the parameter object's public properties and constructors to be preserved.")]
[UnconditionalSuppressMessage("Aot", "IL3050", Justification = "This runtime parameter generator is a fallback for non-intercepted calls and is not used by generated AOT code.")]
internal static Action<IDbCommand, object?> CreateParamInfoGenerator(Identity identity, bool checkForDuplicates, bool removeUnused, IList<LiteralToken> literals)
{
Type type = identity.ParametersType!;
Expand Down
2 changes: 2 additions & 0 deletions Dapper/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Dapper
{
internal static class TypeExtensions
{
[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "All callers use framework types whose public methods are preserved.")]
public static MethodInfo? GetPublicInstanceMethod(this Type type, string name, Type[] types)
=> type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public, null, types, null);
}
Expand Down