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

[V4] Address Native AOT warnings for DynamoDB's Document Model library #3583

Open
wants to merge 1 commit into
base: v4-development
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.Util.Internal;
using System.Diagnostics.CodeAnalysis;


#if NETSTANDARD
using Amazon.Runtime.Internal.Util;
Expand Down Expand Up @@ -71,9 +73,6 @@ internal enum ConversionSchema
/// A collection of converters capable of converting between
/// .NET and DynamoDB objects.
/// </summary>
#if NET8_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
#endif
public class DynamoDBEntryConversion
{
#region Static members
Expand Down Expand Up @@ -252,7 +251,11 @@ public bool TryConvertToEntry(Type inputType, object value, out DynamoDBEntry en
/// <typeparam name="TOutput"></typeparam>
/// <param name="entry"></param>
/// <returns></returns>
#if NET8_0_OR_GREATER
public TOutput ConvertFromEntry<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TOutput>(DynamoDBEntry entry)
#else
public TOutput ConvertFromEntry<TOutput>(DynamoDBEntry entry)
#endif
{
TOutput output;
if (TryConvertFromEntry<TOutput>(entry, out output))
Expand All @@ -269,7 +272,11 @@ public TOutput ConvertFromEntry<TOutput>(DynamoDBEntry entry)
/// <param name="entry"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
#if NET8_0_OR_GREATER
public object ConvertFromEntry([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type outputType, DynamoDBEntry entry)
#else
public object ConvertFromEntry(Type outputType, DynamoDBEntry entry)
#endif
{
if (outputType == null) throw new ArgumentNullException("outputType");
if (entry == null) throw new ArgumentNullException("entry");
Expand All @@ -287,7 +294,11 @@ public object ConvertFromEntry(Type outputType, DynamoDBEntry entry)
/// <param name="entry"></param>
/// <param name="output"></param>
/// <returns>True if successfully converted, otherwise false.</returns>
#if NET8_0_OR_GREATER
public bool TryConvertFromEntry<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TOutput>(DynamoDBEntry entry, out TOutput output)
#else
public bool TryConvertFromEntry<TOutput>(DynamoDBEntry entry, out TOutput output)
#endif
{
output = default(TOutput);

Expand All @@ -313,7 +324,11 @@ public bool TryConvertFromEntry<TOutput>(DynamoDBEntry entry, out TOutput output
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
#if NET8_0_OR_GREATER
public bool TryConvertFromEntry([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type outputType, DynamoDBEntry entry, out object value)
#else
public bool TryConvertFromEntry(Type outputType, DynamoDBEntry entry, out object value)
#endif
{
if (outputType == null) throw new ArgumentNullException("outputType");
if (entry == null) throw new ArgumentNullException("entry");
Expand All @@ -322,7 +337,7 @@ public bool TryConvertFromEntry(Type outputType, DynamoDBEntry entry, out object
return converter.TryFromEntry(entry, outputType, out value);
}

#endregion
#endregion

#region Internal members

Expand Down Expand Up @@ -360,7 +375,12 @@ internal IEnumerable<DynamoDBEntry> ConvertToEntries<T>(IEnumerable<T> values)
//foreach (var value in values)
// yield return ConvertToEntry(value);
}

#if NET8_0_OR_GREATER
internal IEnumerable<object> ConvertFromEntries([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type elementType, IEnumerable<DynamoDBEntry> entries)
#else
internal IEnumerable<object> ConvertFromEntries(Type elementType, IEnumerable<DynamoDBEntry> entries)
#endif
{
if (entries == null) throw new ArgumentNullException("entries");

Expand All @@ -377,7 +397,7 @@ internal PrimitiveList ItemsToPrimitiveList(IEnumerable items)
return pl;
}

#endregion
#endregion

#region Private members

Expand Down Expand Up @@ -539,7 +559,12 @@ public bool TryToEntry(object value, out DynamoDBEntry entry)
entry = null;
return false;
}

#if NET8_0_OR_GREATER
public object FromEntry(DynamoDBEntry entry, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType)
#else
public object FromEntry(DynamoDBEntry entry, Type targetType)
#endif
{
if (entry == null) throw new ArgumentNullException("entry");
if (targetType == null) throw new ArgumentNullException("targetType");
Expand All @@ -551,7 +576,12 @@ public object FromEntry(DynamoDBEntry entry, Type targetType)
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"Unable to convert [{0}] of type {1} to {2}", entry, entry.GetType().FullName, targetType.FullName));
}

#if NET8_0_OR_GREATER
public bool TryFromEntry(DynamoDBEntry entry, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object value)
#else
public bool TryFromEntry(DynamoDBEntry entry, Type targetType, out object value)
#endif
{
var p = entry as Primitive;

Expand Down Expand Up @@ -627,17 +657,32 @@ public virtual bool TryFrom(DynamoDBBool b, Type targetType, out object result)
result = null;
return false;
}

#if NET8_0_OR_GREATER
public virtual bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public virtual bool TryFrom(Primitive p, Type targetType, out object result)
#endif
{
result = null;
return false;
}

#if NET8_0_OR_GREATER
public virtual bool TryFrom(PrimitiveList pl, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public virtual bool TryFrom(PrimitiveList pl, Type targetType, out object result)
#endif
{
result = null;
return false;
}

#if NET8_0_OR_GREATER
public virtual bool TryFrom(DynamoDBList l, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public virtual bool TryFrom(DynamoDBList l, Type targetType, out object result)
#endif
{
result = null;
return false;
Expand All @@ -651,19 +696,6 @@ public virtual bool TryFrom(Document d, Type targetType, out object result)

internal abstract class Converter<T> : Converter
{
public override IEnumerable<Type> GetTargetTypes()
Copy link
Member Author

@normj normj Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this override in the abstract class to instead have the final subclasses return their target types without using unbounded reflection.

{
var type = typeof(T);
yield return type;

if (type.IsValueType)
{
//yield return typeof(Nullable<T>);
var nullableType = typeof(Nullable<>).MakeGenericType(type);
yield return nullableType;
}
}

public override bool TryTo(object value, out DynamoDBBool b)
{
return TryTo((T)value, out b);
Expand Down Expand Up @@ -718,21 +750,36 @@ public override bool TryFrom(DynamoDBBool b, Type targetType, out object result)
result = t;
return output;
}

#if NET8_0_OR_GREATER
public override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public override bool TryFrom(Primitive p, Type targetType, out object result)
#endif
{
T t;
var output = TryFrom(p, targetType, out t);
result = t;
return output;
}

#if NET8_0_OR_GREATER
public override bool TryFrom(PrimitiveList pl, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public override bool TryFrom(PrimitiveList pl, Type targetType, out object result)
#endif
{
T t;
var output = TryFrom(pl, targetType, out t);
result = t;
return output;
}

#if NET8_0_OR_GREATER
public override bool TryFrom(DynamoDBList l, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out object result)
#else
public override bool TryFrom(DynamoDBList l, Type targetType, out object result)
#endif
{
T t;
var output = TryFrom(l, targetType, out t);
Expand All @@ -752,7 +799,12 @@ protected virtual bool TryFrom(DynamoDBBool b, Type targetType, out T result)
result = default(T);
return false;
}

#if NET8_0_OR_GREATER
protected virtual bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out T result)
#else
protected virtual bool TryFrom(Primitive p, Type targetType, out T result)
#endif
{
result = default(T);
return false;
Expand Down
Loading
Loading