diff --git a/generator/.DevConfigs/7FE49E8F-93BF-419E-B3B2-265D9D6F35E3.json b/generator/.DevConfigs/7FE49E8F-93BF-419E-B3B2-265D9D6F35E3.json new file mode 100644 index 000000000000..07e440dbc7e2 --- /dev/null +++ b/generator/.DevConfigs/7FE49E8F-93BF-419E-B3B2-265D9D6F35E3.json @@ -0,0 +1,18 @@ +{ + "core": { + "changeLogMessages": [ + "Backport the .NET trimming attributes like DynamicallyAccessedMembersAttribute into ThirdParty.RuntimeBackports namespace for Target Frameworks before .NET 8. This simplifies the SDK's codebase by removing compilation conditional checks when using the attributes." + ], + "type": "patch", + "updateMinimum": true + }, + "services": [ + { + "serviceName": "DynamoDBv2", + "type": "patch", + "changeLogMessages": [ + "Add NativeAOT support for the DataModel namespace also known as the Object Persistence high level library." + ] + } + ] +} \ No newline at end of file diff --git a/sdk/src/Core/Amazon.Runtime/ClientContext.cs b/sdk/src/Core/Amazon.Runtime/ClientContext.cs index b0af3d902dcc..200f1214cb8f 100644 --- a/sdk/src/Core/Amazon.Runtime/ClientContext.cs +++ b/sdk/src/Core/Amazon.Runtime/ClientContext.cs @@ -22,6 +22,8 @@ using Amazon.Util.Internal; using Amazon.Util.Internal.PlatformServices; using Amazon.Runtime; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal { @@ -29,11 +31,9 @@ namespace Amazon.Runtime.Internal /// This class composes Client Context header for Amazon Web Service client. /// It contains information like app title, version code, version name, client id, OS platform etc. /// -#if NET8_0_OR_GREATER // This class wasn't updated to use source generators because the object to JSON method uses the non generic IDictionary. Usage of this class is probably very low since it is not used directly // by the SDK and it is in an internal namespace. - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually.")] -#endif + [RequiresUnreferencedCode("ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually.")] public partial class ClientContext { //client related keys diff --git a/sdk/src/Core/Amazon.Runtime/ConstantClass.cs b/sdk/src/Core/Amazon.Runtime/ConstantClass.cs index f0d0636bdac3..3526b43d88c9 100644 --- a/sdk/src/Core/Amazon.Runtime/ConstantClass.cs +++ b/sdk/src/Core/Amazon.Runtime/ConstantClass.cs @@ -27,15 +27,14 @@ using System.Text; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime { /// /// Base class for constant class that holds the value that will be sent to AWS for the static constants. /// -#if NET8_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] -#endif public class ConstantClass { static readonly object staticFieldsLock = new object(); @@ -91,11 +90,7 @@ internal ConstantClass Intern() return map.TryGetValue(this.Value, out foundValue) ? foundValue : this; } -#if NET8_0_OR_GREATER protected static T FindValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicConstructors)] T>(string value) where T : ConstantClass -#else - protected static T FindValue(string value) where T : ConstantClass -#endif { if (value == null) return null; @@ -115,11 +110,7 @@ protected static T FindValue(string value) where T : ConstantClass return foundValue as T; } -#if NET8_0_OR_GREATER private static void LoadFields([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type type) -#else - private static void LoadFields(Type type) -#endif { if (staticFields.ContainsKey(type)) return; diff --git a/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleAWSCredentials.cs b/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleAWSCredentials.cs index 69823fafbea8..3ec6c4ee5a31 100644 --- a/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleAWSCredentials.cs +++ b/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleAWSCredentials.cs @@ -20,6 +20,8 @@ using System; using System.Globalization; using System.Net; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime { @@ -89,10 +91,8 @@ public AssumeRoleAWSCredentials(AWSCredentials sourceCredentials, string roleArn PreemptExpiryTime = TimeSpan.FromMinutes(15); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif protected override CredentialsRefreshState GenerateNewCredentials() { var region = FallbackRegionFactory.GetRegionEndpoint() ?? DefaultSTSClientRegion; diff --git a/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleWithWebIdentityCredentials.cs b/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleWithWebIdentityCredentials.cs index 44161726c940..77634e2ac81d 100644 --- a/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleWithWebIdentityCredentials.cs +++ b/sdk/src/Core/Amazon.Runtime/Credentials/AssumeRoleWithWebIdentityCredentials.cs @@ -18,7 +18,9 @@ using Amazon.RuntimeDependencies; using Amazon.Util; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Net; @@ -222,10 +224,8 @@ protected override async Task GenerateNewCredentialsAsy /// Gets a client to be used for AssumeRoleWithWebIdentity requests. /// /// The STS client. -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif protected virtual ICoreAmazonSTS_WebIdentity CreateClient() { var region = FallbackRegionFactory.GetRegionEndpoint() ?? _defaultSTSClientRegion; diff --git a/sdk/src/Core/Amazon.Runtime/Credentials/FederatedAWSCredentials.cs b/sdk/src/Core/Amazon.Runtime/Credentials/FederatedAWSCredentials.cs index 5763da91b429..4eb3e73028cc 100644 --- a/sdk/src/Core/Amazon.Runtime/Credentials/FederatedAWSCredentials.cs +++ b/sdk/src/Core/Amazon.Runtime/Credentials/FederatedAWSCredentials.cs @@ -21,7 +21,9 @@ using Amazon.Util; using Amazon.RuntimeDependencies; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; using System; +using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Globalization; using System.Net; @@ -177,10 +179,8 @@ protected override CredentialsRefreshState GenerateNewCredentials() return newState; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif private CredentialsRefreshState Authenticate(ICredentials userCredential) { CredentialsRefreshState state; diff --git a/sdk/src/Core/Amazon.Runtime/Credentials/URIBasedRefreshingCredentialHelper.cs b/sdk/src/Core/Amazon.Runtime/Credentials/URIBasedRefreshingCredentialHelper.cs index 37f11f58161a..73f589324270 100644 --- a/sdk/src/Core/Amazon.Runtime/Credentials/URIBasedRefreshingCredentialHelper.cs +++ b/sdk/src/Core/Amazon.Runtime/Credentials/URIBasedRefreshingCredentialHelper.cs @@ -17,9 +17,11 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net; using ThirdParty.Json.LitJson; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime { @@ -50,27 +52,21 @@ protected static string GetContents(Uri uri, IWebProxy proxy, Dictionary(Uri uri) { return GetObjectFromResponse(uri, null, null); } [Obsolete("This method is not compatible with Native AOT builds. The GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] -#endif + [RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] protected static T GetObjectFromResponse(Uri uri, IWebProxy proxy) { return GetObjectFromResponse(uri, proxy, null); } [Obsolete("This method is not compatible with Native AOT builds. The GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] -#endif + [RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")] protected static T GetObjectFromResponse(Uri uri, IWebProxy proxy, Dictionary headers) { string json = GetContents(uri, proxy, headers); diff --git a/sdk/src/Core/Amazon.Runtime/Documents/Document.cs b/sdk/src/Core/Amazon.Runtime/Documents/Document.cs index 16c100907e00..dff09625a553 100644 --- a/sdk/src/Core/Amazon.Runtime/Documents/Document.cs +++ b/sdk/src/Core/Amazon.Runtime/Documents/Document.cs @@ -17,9 +17,11 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using ThirdParty.Json.LitJson; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Documents { @@ -410,9 +412,7 @@ public override string ToString() /// for performance critical work. Additionally, if is a known primitive (ie ), /// using a constructor directly will be more performant. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] -#endif + [RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] public static Document FromObject(object o) { IJsonWrapper jsonData = JsonMapper.ToObject(JsonMapper.ToJson(o)); @@ -420,9 +420,7 @@ public static Document FromObject(object o) return FromObject(jsonData); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] -#endif + [RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] private static Document FromObject(IJsonWrapper jsonData) { switch (jsonData.GetJsonType()) @@ -450,9 +448,7 @@ private static Document FromObject(IJsonWrapper jsonData) throw new NotSupportedException($"Couldn't convert {jsonData.GetJsonType()}"); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] -#endif + [RequiresUnreferencedCode("FromObject is not currently supported for Native AOT compilation due unbounded reflection required.")] private static void Copy(IDictionary source, Dictionary target) { foreach (var key in source.Keys) diff --git a/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EnumerableEventStream.cs b/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EnumerableEventStream.cs index d75ec08ed3d3..6b8b0f1bb22e 100644 --- a/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EnumerableEventStream.cs +++ b/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EnumerableEventStream.cs @@ -30,6 +30,8 @@ using System.Threading.Tasks; #endif +using ThirdParty.RuntimeBackports; + namespace Amazon.Runtime.EventStreams.Internal { /// @@ -49,11 +51,7 @@ namespace Amazon.Runtime.EventStreams.Internal /// An implementation of EventStreamException (e.g. S3EventStreamException). [SuppressMessage("Microsoft.Naming", "CA1710", Justification = "EventStreamCollection is not descriptive.")] [SuppressMessage("Microsoft.Design", "CA1063", Justification = "IDisposable is a transient interface from IEventStream. Users need to be able to call Dispose.")] -#if NET8_0_OR_GREATER public abstract class EnumerableEventStream : EventStream, IEnumerableEventStream, IAsyncEnumerable where T : IEventStreamEvent where TE : EventStreamException, new() -#else - public abstract class EnumerableEventStream : EventStream, IEnumerableEventStream, IAsyncEnumerable where T : IEventStreamEvent where TE : EventStreamException, new() -#endif { private const string MutuallyExclusiveExceptionMessage = "Stream has already begun processing. Event-driven and Enumerable traversals of the stream are mutually exclusive. " + "You can either use the event driven or enumerable interface, but not both."; diff --git a/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EventStream.cs b/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EventStream.cs index a7fee63cb083..f594c1c127f2 100644 --- a/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EventStream.cs +++ b/sdk/src/Core/Amazon.Runtime/EventStreams/Internal/EventStream.cs @@ -18,6 +18,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading; +using ThirdParty.RuntimeBackports; #if AWS_ASYNC_API using System.Threading.Tasks; @@ -67,11 +68,7 @@ namespace Amazon.Runtime.EventStreams.Internal /// /// An implementation of IEventStreamEvent (e.g. IS3Event). /// An implementation of EventStreamException (e.g. S3EventStreamException). -#if NET8_0_OR_GREATER public abstract class EventStream : IEventStream where T : IEventStreamEvent where TE : EventStreamException, new() -#else - public abstract class EventStream : IEventStream where T : IEventStreamEvent where TE : EventStreamException, new() -#endif { /// /// "Unique" key for unknown event lookup. diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Auth/AWS4aSignerCRTWrapper.cs b/sdk/src/Core/Amazon.Runtime/Internal/Auth/AWS4aSignerCRTWrapper.cs index 2edb3555f37d..531584fda4ba 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Auth/AWS4aSignerCRTWrapper.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Auth/AWS4aSignerCRTWrapper.cs @@ -18,8 +18,10 @@ using Amazon.Util.Internal; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal.Auth { @@ -46,12 +48,10 @@ public AWS4aSignerCRTWrapper() : this(true) /// Instantiates an SigV4a signer using CRT's SigV4a implementation /// /// Whether to sign the request's payload -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif public AWS4aSignerCRTWrapper(bool signPayload) { if (_awsSigV4AProvider == null) diff --git a/sdk/src/Core/Amazon.Runtime/Internal/ServiceClientHelpers.cs b/sdk/src/Core/Amazon.Runtime/Internal/ServiceClientHelpers.cs index b6daef4ac7b1..9d22d29afdc0 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/ServiceClientHelpers.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/ServiceClientHelpers.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Reflection; using System.Runtime.CompilerServices; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal { @@ -25,12 +27,8 @@ public static class ServiceClientHelpers public const string STS_SERVICE_CLASS_NAME = "Amazon.SecurityToken.AmazonSecurityTokenServiceClient"; public const string STS_SERVICE_CONFIG_NAME = "Amazon.SecurityToken.AmazonSecurityTokenServiceConfig"; -#if NET8_0_OR_GREATER - public static TClient CreateServiceFromAnother<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] TClient, - [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] TConfig>(AmazonServiceClient originalServiceClient) -#else - public static TClient CreateServiceFromAnother(AmazonServiceClient originalServiceClient) -#endif + public static TClient CreateServiceFromAnother<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TClient, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConfig>(AmazonServiceClient originalServiceClient) where TConfig : ClientConfig, new () where TClient : AmazonServiceClient { @@ -50,9 +48,7 @@ public static TClient CreateServiceFromAnother(AmazonServiceCl return newServiceClient; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] public static TClient CreateServiceFromAssembly(string assemblyName, string serviceClientClassName, RegionEndpoint region) where TClient : class @@ -69,9 +65,7 @@ public static TClient CreateServiceFromAssembly(string assemblyName, st return newServiceClient; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] public static TClient CreateServiceFromAssembly(string assemblyName, string serviceClientClassName, AWSCredentials credentials, RegionEndpoint region) where TClient : class @@ -89,9 +83,7 @@ public static TClient CreateServiceFromAssembly(string assemblyName, st return newServiceClient; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] public static TClient CreateServiceFromAssembly(string assemblyName, string serviceClientClassName, AWSCredentials credentials, ClientConfig config) where TClient : class @@ -109,9 +101,7 @@ public static TClient CreateServiceFromAssembly(string assemblyName, st return newServiceClient; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code should use Amazon.RuntimeDependencyRegistry to use explicitly provided runtime dependencies.")] public static TClient CreateServiceFromAssembly(string assemblyName, string serviceClientClassName, AmazonServiceClient originalServiceClient) where TClient : class { @@ -131,9 +121,7 @@ public static TClient CreateServiceFromAssembly(string assemblyName, st return newServiceClient; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] public static ClientConfig CreateServiceConfig(string assemblyName, string serviceConfigClassName) { var typeInfo = LoadServiceConfigType(assemblyName, serviceConfigClassName); @@ -144,25 +132,19 @@ public static ClientConfig CreateServiceConfig(string assemblyName, string servi return config as ClientConfig; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] private static Type LoadServiceClientType(string assemblyName, string serviceClientClassName) { return LoadTypeFromAssembly(assemblyName, serviceClientClassName); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] private static Type LoadServiceConfigType(string assemblyName, string serviceConfigClassName) { return LoadTypeFromAssembly(assemblyName, serviceConfigClassName); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] internal static Type LoadTypeFromAssembly(string assemblyName, string className) { var assembly = GetSDKAssembly(assemblyName); @@ -171,9 +153,7 @@ internal static Type LoadTypeFromAssembly(string assemblyName, string className) return type; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using ServiceClientHelper to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] private static Assembly GetSDKAssembly(string assemblyName) { return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => string.Equals(x.GetName().Name, assemblyName, StringComparison.Ordinal)) diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumCRTWrapper.cs b/sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumCRTWrapper.cs index 2af5ebd8b316..24d763d20739 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumCRTWrapper.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumCRTWrapper.cs @@ -22,6 +22,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; +using ThirdParty.RuntimeBackports; namespace AWSSDK.Runtime.Internal.Util { @@ -38,12 +39,10 @@ public static class ChecksumCRTWrapper private static volatile IChecksumProvider _instance; -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif private static IChecksumProvider Instance { get diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.Log4net.cs b/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.Log4net.cs index 28cf6db396cb..f495fe851c11 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.Log4net.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.Log4net.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ using System; +using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; @@ -21,15 +22,14 @@ using System.ComponentModel; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal.Util { /// /// Logger wrapper for reflected log4net logging methods. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("SDK logging to Log4net is not supported when trimming is enabled.")] -#endif + [RequiresUnreferencedCode("SDK logging to Log4net is not supported when trimming is enabled.")] internal class InternalLog4netLogger : InternalLogger { enum LoadState { Uninitialized, Failed, Loading, Success }; diff --git a/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.cs b/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.cs index b50c525b6dd7..9658bd547953 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/Util/Logger.cs @@ -16,12 +16,14 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; using System.Text; using System.ComponentModel; using Amazon.Runtime; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal.Util { @@ -40,10 +42,8 @@ private Logger() loggers = new List(); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Constructor looks to see if running in a NativeAOT environment and if so skips the Log4net internal logger which is not Native AOT complaint.")] -#endif private Logger(Type type) { loggers = new List(); diff --git a/sdk/src/Core/Amazon.Runtime/Internal/_bcl+netstandard/SSOServiceClientHelpers.cs b/sdk/src/Core/Amazon.Runtime/Internal/_bcl+netstandard/SSOServiceClientHelpers.cs index 448496ec1758..92930339af4e 100644 --- a/sdk/src/Core/Amazon.Runtime/Internal/_bcl+netstandard/SSOServiceClientHelpers.cs +++ b/sdk/src/Core/Amazon.Runtime/Internal/_bcl+netstandard/SSOServiceClientHelpers.cs @@ -1,10 +1,12 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net; using Amazon.Runtime.Internal.Util; using Amazon.Runtime.SharedInterfaces; using Amazon.RuntimeDependencies; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.Runtime.Internal { @@ -12,10 +14,8 @@ namespace Amazon.Runtime.Internal /// Collection of helper methods for constructing the necessary Service client to /// interrogate AWS SSO Services. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif public static class SSOServiceClientHelpers { public static ICoreAmazonSSOOIDC BuildSSOIDCClient( @@ -42,10 +42,8 @@ public static ICoreAmazonSSOOIDC BuildSSOIDCClient( return coreSSO; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif public static ICoreAmazonSSO BuildSSOClient( RegionEndpoint region, #if BCL @@ -69,10 +67,8 @@ public static ICoreAmazonSSO BuildSSOClient( return coreSSO; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif public static ICoreAmazonSSO_Logout BuildSSOLogoutClient( RegionEndpoint region, #if BCL @@ -96,10 +92,8 @@ public static ICoreAmazonSSO_Logout BuildSSOLogoutClient( return coreSSOLogout; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] -#endif public static ICoreAmazonSSOOIDC_V2 BuildSSOIDC_V2Client( RegionEndpoint region, #if BCL @@ -127,9 +121,7 @@ public static ICoreAmazonSSOOIDC_V2 BuildSSOIDC_V2Client( /// /// Attempts to get a service client at runtime which cannot be made a project reference. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Using CreateClient to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] -#endif + [RequiresUnreferencedCode("Using CreateClient to dynamically load dependency is not supported for Native AOT. SDK calling code must use Amazon.RuntimeDependencyRegistry to explicitly provide runtime dependencies.")] private static T CreateClient( RegionEndpoint region, string serviceClassName, diff --git a/sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs b/sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs index 0bcff9ba1fff..b1ad39487b0d 100644 --- a/sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs +++ b/sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs @@ -24,6 +24,7 @@ using Amazon.Util.Internal.PlatformServices; using System.Text; using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.Util.Internal { @@ -177,11 +178,7 @@ public static void ApplyValues(object target, IDictionary proper } } -#if NET8_0_OR_GREATER public static void ApplyValuesV2<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, IDictionary propertyValues) -#else - public static void ApplyValuesV2(T target, IDictionary propertyValues) -#endif { if (propertyValues == null || propertyValues.Count == 0) return; diff --git a/sdk/src/Core/Amazon.Util/Internal/JsonSerializerHelper.cs b/sdk/src/Core/Amazon.Util/Internal/JsonSerializerHelper.cs index 9ec8a9bdad75..55935ddbdcc2 100644 --- a/sdk/src/Core/Amazon.Util/Internal/JsonSerializerHelper.cs +++ b/sdk/src/Core/Amazon.Util/Internal/JsonSerializerHelper.cs @@ -121,7 +121,9 @@ public class JsonSerializerOptions public bool WriteIndented {get;set;} } +#pragma warning disable CA1019 // Since this is a dummy implementation of JsonSerializableAttribute for pre .NET 8 targets we don't need the accessor. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - internal sealed class JsonSerializableAttribute : Attribute { internal JsonSerializableAttribute(Type type) { } } + public sealed class JsonSerializableAttribute : Attribute { public JsonSerializableAttribute(Type type) { } } +#pragma warning restore CA1019 #endif } diff --git a/sdk/src/Core/RuntimeDependencies/CreateInstanceContext.cs b/sdk/src/Core/RuntimeDependencies/CreateInstanceContext.cs index f8db3287f693..c8ff3e8a3a31 100644 --- a/sdk/src/Core/RuntimeDependencies/CreateInstanceContext.cs +++ b/sdk/src/Core/RuntimeDependencies/CreateInstanceContext.cs @@ -26,7 +26,7 @@ public class CreateInstanceContext /// /// The type of context. /// - public enum ContextType + public enum ContextType { /// /// Context for creating AmazonSecurityTokenServiceClient @@ -56,7 +56,12 @@ public enum ContextType /// /// Context for creating AmazonSSOOIDCClient /// - SSOOIDCClient + SSOOIDCClient, + + /// + /// Context for creating AmazonS3Client + /// + S3ClientContext } /// @@ -119,6 +124,16 @@ public CreateInstanceContext(SSOOIDCClientContext context) Type = ContextType.SSOOIDCClient; } + /// + /// Create an instance of CreateInstanceContext with the SSOOIDCClientContext context + /// + /// + public CreateInstanceContext(S3ClientContext context) + { + S3ClientContextData = context; + Type = ContextType.S3ClientContext; + } + /// /// The type of context being sent into the factory method. For each type there is a corresponding Data property set containing any relevant information that can be /// used for creating the dependency instance. @@ -154,6 +169,11 @@ public CreateInstanceContext(SSOOIDCClientContext context) /// Data for the SOOIDCClient context /// public SSOOIDCClientContext SSOOIDCClientContextData { get; } + + /// + /// Data for the AmazonS3Client context + /// + public S3ClientContext S3ClientContextData {get;} } @@ -261,4 +281,26 @@ public class SSOOIDCClientContext /// public IWebProxy ProxySettings { get; set; } } + + /// + /// Context for the factory method to create the AmazonS3Client runtime dependency. + /// + public class S3ClientContext + { + /// + /// The possibly actions the AmazonS3Client will be created for. + /// + public enum ActionContext { DynamoBDS3Link }; + + + /// + /// The action the AmazonS3Client is being created for. For example creating an S3 client for the DynamoDB S3 Link feature. + /// + public ActionContext Action { get; set; } + + /// + /// The region the SDK expects the S3 client to be configured for. + /// + public RegionEndpoint Region { get; set; } + } } diff --git a/sdk/src/Core/RuntimeDependencies/GlobalRuntimeDependencyRegistry.cs b/sdk/src/Core/RuntimeDependencies/GlobalRuntimeDependencyRegistry.cs index 48598d8d2284..443db2a10c46 100644 --- a/sdk/src/Core/RuntimeDependencies/GlobalRuntimeDependencyRegistry.cs +++ b/sdk/src/Core/RuntimeDependencies/GlobalRuntimeDependencyRegistry.cs @@ -142,5 +142,27 @@ public void RegisterSSOOIDCClient(RuntimeDependencyFactory factory) { RegisterInstance(ServiceClientHelpers.SSO_OIDC_ASSEMBLY_NAME, ServiceClientHelpers.SSO_OIDC_SERVICE_CLASS_NAME, factory); } + + /// + /// Register the Amazon.S3.AmazonS3Client instance from the AWSSDK.S3 package. + /// + /// The S3 client is used by the DynamoDB high level feature called S3 link. + /// + /// + public void RegisterS3Client(object instance) + { + RegisterInstance(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, instance); + } + + /// + /// Register the Amazon.S3.AmazonS3Client instance from the AWSSDK.S3 package. + /// + /// The S3 client is used by the DynamoDB high level feature called S3 link. + /// + /// + public void RegisterS3Client(RuntimeDependencyFactory factory) + { + RegisterInstance(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, factory); + } } } diff --git a/sdk/src/Core/ThirdParty/Json/JsonMapper.cs b/sdk/src/Core/ThirdParty/Json/JsonMapper.cs index e47b6331ff03..645a5227071c 100644 --- a/sdk/src/Core/ThirdParty/Json/JsonMapper.cs +++ b/sdk/src/Core/ThirdParty/Json/JsonMapper.cs @@ -21,6 +21,7 @@ using Amazon.Util; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace ThirdParty.Json.LitJson { @@ -172,9 +173,7 @@ static JsonMapper () #region Private Methods -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static void AddArrayMetadata (Type type) { if (array_metadata.ContainsKey (type)) @@ -210,9 +209,7 @@ private static void AddArrayMetadata (Type type) } } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static void AddObjectMetadata (Type type) { if (object_metadata.ContainsKey (type)) @@ -268,9 +265,7 @@ private static void AddObjectMetadata (Type type) } } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static void AddTypeProperties (Type type) { if (type_properties.ContainsKey (type)) @@ -307,9 +302,7 @@ private static void AddTypeProperties (Type type) } } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static MethodInfo GetConvOp (Type t1, Type t2) { lock (conv_ops_lock) { @@ -334,9 +327,7 @@ private static MethodInfo GetConvOp (Type t1, Type t2) return op; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static object ReadValue (Type inst_type, JsonReader reader) { reader.Read (); @@ -507,9 +498,7 @@ private static object ReadValue (Type inst_type, JsonReader reader) return instance; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static void ValidateRequiredFields(object instance, Type inst_type) { foreach (var prop in inst_type.GetProperties()) @@ -765,9 +754,7 @@ private static void RegisterImporter ( table[json_type][value_type] = importer; } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] private static void WriteValue (object obj, JsonWriter writer, bool writer_is_private, int depth) @@ -919,9 +906,7 @@ private static void WriteValue (object obj, JsonWriter writer, } #endregion -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] public static string ToJson (object obj) { lock (static_writer_lock) { @@ -933,9 +918,7 @@ public static string ToJson (object obj) } } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] public static void ToJson (object obj, JsonWriter writer) { WriteValue (obj, writer, false, 0); @@ -961,17 +944,13 @@ public static JsonData ToObject (string json) delegate { return new JsonData (); }, json); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] public static T ToObject(JsonReader reader) { return (T) ReadValue (typeof (T), reader); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] public static T ToObject (TextReader reader) { JsonReader json_reader = new JsonReader (reader); @@ -979,9 +958,7 @@ public static T ToObject (TextReader reader) return (T) ReadValue (typeof (T), json_reader); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] -#endif + [RequiresUnreferencedCode("JsonMapper requires reflection of unknown types. System.Text.Json should be used instead.")] public static T ToObject (string json) { JsonReader reader = new JsonReader (json); diff --git a/sdk/src/Core/ThirdParty/RuntimeBackports/TrimmingAttributes.cs b/sdk/src/Core/ThirdParty/RuntimeBackports/TrimmingAttributes.cs new file mode 100644 index 000000000000..92ace5bbb350 --- /dev/null +++ b/sdk/src/Core/ThirdParty/RuntimeBackports/TrimmingAttributes.cs @@ -0,0 +1,160 @@ +// Partially adapted from: +// https://raw.githubusercontent.com/dotnet/runtime/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs +// https://raw.githubusercontent.com/dotnet/runtime/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs +// https://raw.githubusercontent.com/dotnet/runtime/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/UnconditionalSuppressMessageAttribute.cs +// https://raw.githubusercontent.com/dotnet/runtime/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnreferencedCodeAttribute.cs +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !NET8_0_OR_GREATER +using System; + +namespace ThirdParty.RuntimeBackports +{ + [Flags] +#pragma warning disable CA2217 // Do not mark enums with FlagsAttribute + public enum DynamicallyAccessedMemberTypes +#pragma warning restore CA2217 // Do not mark enums with FlagsAttribute + { + All = -1, + None = 0, + PublicParameterlessConstructor = 1, + PublicConstructors = 3, + NonPublicConstructors = 4, + PublicMethods = 8, + NonPublicMethods = 16, + PublicFields = 32, + NonPublicFields = 64, + PublicNestedTypes = 128, + NonPublicNestedTypes = 256, + PublicProperties = 512, + NonPublicProperties = 1024, + PublicEvents = 2048, + NonPublicEvents = 4096, + Interfaces = 8192 + } + + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | + AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, + Inherited = false)] + + public sealed class DynamicallyAccessedMembersAttribute : Attribute + { + /// + /// Initializes a new instance of the class + /// with the specified member types. + /// + /// The types of members dynamically accessed. + public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes) + { + MemberTypes = memberTypes; + } + + /// + /// Gets the which specifies the type + /// of members dynamically accessed. + /// + public DynamicallyAccessedMemberTypes MemberTypes { get; } + } + + [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] + public sealed class UnconditionalSuppressMessageAttribute : Attribute + { + /// + /// Initializes a new instance of the + /// class, specifying the category of the tool and the identifier for an analysis rule. + /// + /// The category for the attribute. + /// The identifier of the analysis rule the attribute applies to. + public UnconditionalSuppressMessageAttribute(string category, string checkId) + { + Category = category; + CheckId = checkId; + } + + /// + /// Gets the category identifying the classification of the attribute. + /// + /// + /// The property describes the tool or tool analysis category + /// for which a message suppression attribute applies. + /// + public string Category { get; } + + /// + /// Gets the identifier of the analysis tool rule to be suppressed. + /// + /// + /// Concatenated together, the and + /// properties form a unique check identifier. + /// + public string CheckId { get; } + + /// + /// Gets or sets the scope of the code that is relevant for the attribute. + /// + /// + /// The Scope property is an optional argument that specifies the metadata scope for which + /// the attribute is relevant. + /// + public string Scope { get; set; } + + /// + /// Gets or sets a fully qualified path that represents the target of the attribute. + /// + /// + /// The property is an optional argument identifying the analysis target + /// of the attribute. An example value is "System.IO.Stream.ctor():System.Void". + /// Because it is fully qualified, it can be long, particularly for targets such as parameters. + /// The analysis tool user interface should be capable of automatically formatting the parameter. + /// + public string Target { get; set; } + + /// + /// Gets or sets an optional argument expanding on exclusion criteria. + /// + /// + /// The property is an optional argument that specifies additional + /// exclusion where the literal metadata target is not sufficiently precise. For example, + /// the cannot be applied within a method, + /// and it may be desirable to suppress a violation against a statement in the method that will + /// give a rule violation, but not against all statements in the method. + /// + public string MessageId { get; set; } + + /// + /// Gets or sets the justification for suppressing the code analysis message. + /// + public string Justification { get; set; } + } + + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)] + public sealed class RequiresUnreferencedCodeAttribute : Attribute + { + /// + /// Initializes a new instance of the class + /// with the specified message. + /// + /// + /// A message that contains information about the usage of unreferenced code. + /// + public RequiresUnreferencedCodeAttribute(string message) + { + Message = message; + } + + /// + /// Gets a message that contains information about the usage of unreferenced code. + /// + public string Message { get; } + + /// + /// Gets or sets an optional URL that contains more information about the method, + /// why it requries unreferenced code, and what options a consumer has to deal with it. + /// + public string Url { get; set; } + } +} +#endif \ No newline at end of file diff --git a/sdk/src/Services/DynamoDBv2/Custom/AWSConfigs.DynamoDB.cs b/sdk/src/Services/DynamoDBv2/Custom/AWSConfigs.DynamoDB.cs index d964880252bb..0b5de0605a6f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/AWSConfigs.DynamoDB.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/AWSConfigs.DynamoDB.cs @@ -15,6 +15,8 @@ using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; using Amazon.DynamoDBv2.DataModel; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon { @@ -332,6 +334,7 @@ public partial class PropertyConfig /// /// The type of converter that should be used on this property /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] public Type Converter { get; set; } /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/Conversion/DynamoDBEntryConversion.cs b/sdk/src/Services/DynamoDBv2/Custom/Conversion/DynamoDBEntryConversion.cs index dcb49a30bbab..7b8a68a35a42 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Conversion/DynamoDBEntryConversion.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Conversion/DynamoDBEntryConversion.cs @@ -21,6 +21,7 @@ using Amazon.DynamoDBv2.DocumentModel; using Amazon.Util.Internal; using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; #if NETSTANDARD @@ -251,11 +252,7 @@ public bool TryConvertToEntry(Type inputType, object value, out DynamoDBEntry en /// /// /// -#if NET8_0_OR_GREATER public TOutput ConvertFromEntry<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TOutput>(DynamoDBEntry entry) -#else - public TOutput ConvertFromEntry(DynamoDBEntry entry) -#endif { TOutput output; if (TryConvertFromEntry(entry, out output)) @@ -272,11 +269,7 @@ public TOutput ConvertFromEntry(DynamoDBEntry entry) /// /// /// -#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"); @@ -294,11 +287,7 @@ public object ConvertFromEntry(Type outputType, DynamoDBEntry entry) /// /// /// True if successfully converted, otherwise false. -#if NET8_0_OR_GREATER public bool TryConvertFromEntry<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TOutput>(DynamoDBEntry entry, out TOutput output) -#else - public bool TryConvertFromEntry(DynamoDBEntry entry, out TOutput output) -#endif { output = default(TOutput); @@ -324,11 +313,7 @@ public bool TryConvertFromEntry(DynamoDBEntry entry, out TOutput output /// /// /// -#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"); @@ -376,11 +361,7 @@ internal IEnumerable ConvertToEntries(IEnumerable values) // yield return ConvertToEntry(value); } -#if NET8_0_OR_GREATER internal IEnumerable ConvertFromEntries([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type elementType, IEnumerable entries) -#else - internal IEnumerable ConvertFromEntries(Type elementType, IEnumerable entries) -#endif { if (entries == null) throw new ArgumentNullException("entries"); @@ -560,11 +541,7 @@ public bool TryToEntry(object value, out DynamoDBEntry entry) 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"); @@ -577,11 +554,7 @@ public object FromEntry(DynamoDBEntry entry, Type targetType) "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; @@ -658,31 +631,19 @@ public virtual bool TryFrom(DynamoDBBool b, Type targetType, out object result) 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; @@ -751,11 +712,7 @@ public override bool TryFrom(DynamoDBBool b, Type targetType, out object result) 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); @@ -763,11 +720,7 @@ public override bool TryFrom(Primitive p, Type targetType, out object result) 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); @@ -775,11 +728,7 @@ public override bool TryFrom(PrimitiveList pl, Type targetType, out object resul 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); @@ -800,11 +749,7 @@ protected virtual bool TryFrom(DynamoDBBool b, Type targetType, out T result) 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; diff --git a/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV1.cs b/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV1.cs index a2f580fb4147..3c01f34b2873 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV1.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV1.cs @@ -17,6 +17,7 @@ using Amazon.DynamoDBv2.DocumentModel; using Amazon.Runtime.Internal.Util; using Amazon.Util; +using ThirdParty.RuntimeBackports; using System; using System.Collections; using System.Collections.Generic; @@ -44,11 +45,7 @@ protected override bool TryTo(byte value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out byte result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out byte result) -#endif { return byte.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -67,11 +64,7 @@ protected override bool TryTo(sbyte value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out sbyte result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out sbyte result) -#endif { return SByte.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -90,11 +83,7 @@ protected override bool TryTo(ushort value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out ushort result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out ushort result) -#endif { return UInt16.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -113,11 +102,7 @@ protected override bool TryTo(short value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out short result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out short result) -#endif { return Int16.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -136,11 +121,7 @@ protected override bool TryTo(uint value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out uint result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out uint result) -#endif { return UInt32.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -159,11 +140,7 @@ protected override bool TryTo(int value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out int result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out int result) -#endif { return Int32.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -182,11 +159,7 @@ protected override bool TryTo(ulong value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out ulong result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out ulong result) -#endif { return UInt64.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -205,11 +178,7 @@ protected override bool TryTo(long value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out long result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out long result) -#endif { return Int64.TryParse(p.StringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } @@ -227,11 +196,7 @@ protected override bool TryTo(float value, out Primitive p) p = new Primitive(value.ToString("r", CultureInfo.InvariantCulture), DynamoDBEntryType.Numeric); return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out float result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out float result) -#endif { return Single.TryParse(p.StringValue, NumberStyles.Float, CultureInfo.InvariantCulture, out result); } @@ -250,11 +215,7 @@ protected override bool TryTo(double value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out double result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out double result) -#endif { return Double.TryParse(p.StringValue, NumberStyles.Float, CultureInfo.InvariantCulture, out result); } @@ -272,11 +233,7 @@ protected override bool TryTo(decimal value, out Primitive p) p = new Primitive(value.ToString("g", CultureInfo.InvariantCulture), DynamoDBEntryType.Numeric); return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out decimal result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out decimal result) -#endif { return Decimal.TryParse(p.StringValue, NumberStyles.Float, CultureInfo.InvariantCulture, out result); } @@ -295,11 +252,7 @@ protected override bool TryTo(char value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out char result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out char result) -#endif { return Char.TryParse(p.StringValue, out result); } @@ -318,11 +271,7 @@ protected override bool TryTo(string value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out string result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out string result) -#endif { result = p.StringValue; return (result != null); @@ -343,11 +292,7 @@ protected override bool TryTo(DateTime value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out DateTime result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out DateTime result) -#endif { if (DateTime.TryParseExact(p.StringValue, AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out result)) { @@ -370,11 +315,7 @@ protected override bool TryTo(Guid value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out Guid result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out Guid result) -#endif { result = new Guid(p.StringValue); return true; @@ -394,11 +335,7 @@ protected override bool TryTo(byte[] value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out byte[] result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out byte[] result) -#endif { result = p.Value as byte[]; return (result != null); @@ -418,11 +355,7 @@ protected override bool TryTo(MemoryStream value, out Primitive p) return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out MemoryStream result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out MemoryStream result) -#endif { var bytes = p.Value as byte[]; if (bytes == null) @@ -465,11 +398,7 @@ protected override bool TryTo(Enum value, out Primitive p) return succeeded; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out Enum result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out Enum result) -#endif { result = null; @@ -489,11 +418,7 @@ protected override bool TryFrom(Primitive p, Type targetType, out Enum result) return succeeded; } -#if NET8_0_OR_GREATER private Enum ConvertEnum(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType) -#else - private Enum ConvertEnum(Primitive p, Type targetType) -#endif { object numerical; // convert Primitive to numeric type, using current conversion @@ -544,11 +469,7 @@ protected override bool TryFrom(DynamoDBBool b, Type targetType, out bool result result = b.Value; return true; } -#if NET8_0_OR_GREATER protected override bool TryFrom(Primitive p, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, out bool result) -#else - protected override bool TryFrom(Primitive p, Type targetType, out bool result) -#endif { result = !p.StringValue.Equals("0", StringComparison.OrdinalIgnoreCase); return true; @@ -558,11 +479,7 @@ protected override bool TryFrom(Primitive p, Type targetType, out bool result) internal abstract class CollectionConverter : Converter { -#if NET8_0_OR_GREATER protected bool EntriesToCollection([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type elementType, IEnumerable entries, out object result) -#else - protected bool EntriesToCollection(Type targetType, Type elementType, IEnumerable entries, out object result) -#endif { var items = Conversion.ConvertFromEntries(elementType, entries); return Utils.ItemsToCollection(targetType, items, out result); @@ -597,22 +514,14 @@ public override bool TryTo(object value, out PrimitiveList pl) return false; } -#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 { var elementType = Utils.GetPrimitiveElementType(targetType); var primitives = pl.Entries; return EntriesToCollection(targetType, elementType, pl.Entries.Cast(), out result); } -#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 { var elementType = Utils.GetPrimitiveElementType(targetType); var entries = l.Entries; diff --git a/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV2.cs b/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV2.cs index a506de46d8a8..b9190ac344e1 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV2.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Conversion/SchemaV2.cs @@ -16,6 +16,7 @@ using Amazon.DynamoDBv2.DataModel; using Amazon.DynamoDBv2.DocumentModel; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; using System; using System.Collections; using System.Collections.Generic; @@ -196,11 +197,7 @@ public override bool TryTo(object value, out DynamoDBList l) return false; } -#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 { var elementType = Utils.GetElementType(targetType); var entries = l.Entries; diff --git a/sdk/src/Services/DynamoDBv2/Custom/Conversion/V1PropertyConverters.cs b/sdk/src/Services/DynamoDBv2/Custom/Conversion/V1PropertyConverters.cs index 791b65471724..340be6ec1469 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Conversion/V1PropertyConverters.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Conversion/V1PropertyConverters.cs @@ -25,6 +25,7 @@ using System.Reflection; using System.Text; using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2 { @@ -40,28 +41,19 @@ namespace Amazon.DynamoDBv2 /// The default value for this field is the standard V1 conversion. /// -#if NET8_0_OR_GREATER public class SetPropertyConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TCollection, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] TElement> : IPropertyConverter where TCollection : ICollection, new() -#else - public class SetPropertyConverter : IPropertyConverter - where TCollection : ICollection, new() -#endif { /// /// Reference to the type object for the TCollection generic. /// -#if NET8_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] -#endif protected static readonly Type collectionType = typeof(TCollection); /// /// Reference to the type object for the TElement generic. /// -#if NET8_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] -#endif protected static readonly Type elementType = typeof(TElement); /// @@ -151,9 +143,7 @@ public object FromEntry(DynamoDBEntry entry) /// /// public class ListToSetPropertyConverter< -#if NET8_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] -#endif TElement> : SetPropertyConverter, TElement> { } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Attributes.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Attributes.cs index 77c8231db416..587e0edb36a1 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Attributes.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Attributes.cs @@ -14,7 +14,9 @@ */ using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -176,7 +178,7 @@ public DynamoDBPropertyAttribute(string attributeName) /// Converter must be the type of a class that implements IPropertyConverter. /// /// Custom converter type. - public DynamoDBPropertyAttribute(Type converter) + public DynamoDBPropertyAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) { Converter = converter; } @@ -203,7 +205,7 @@ public DynamoDBPropertyAttribute(bool storeAsEpoch) /// Name of attribute to be associated with property or field. /// /// Custom converter type. - public DynamoDBPropertyAttribute(string attributeName, Type converter) + public DynamoDBPropertyAttribute(string attributeName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) : base(attributeName) { Converter = converter; @@ -230,6 +232,7 @@ public DynamoDBPropertyAttribute(string attributeName, bool storeAsEpoch) /// Type of the custom converter. /// Cannot be set at the same time as StoreAsEpoch. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] public Type Converter { get; set; } /// @@ -275,7 +278,7 @@ public DynamoDBHashKeyAttribute(string attributeName) /// Converter must be the type of a class that implements IPropertyConverter. /// /// Custom converter type. - public DynamoDBHashKeyAttribute(Type converter) + public DynamoDBHashKeyAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) : base(converter) { } @@ -289,7 +292,7 @@ public DynamoDBHashKeyAttribute(Type converter) /// Name of attribute to be associated with property or field. /// /// Custom converter type. - public DynamoDBHashKeyAttribute(string attributeName, Type converter) + public DynamoDBHashKeyAttribute(string attributeName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) : base(attributeName, converter) { } @@ -330,7 +333,7 @@ public DynamoDBRangeKeyAttribute(string attributeName) /// Converter must be the type of a class that implements IPropertyConverter. /// /// Custom converter type. - public DynamoDBRangeKeyAttribute(Type converter) + public DynamoDBRangeKeyAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) : base(converter) { } @@ -344,7 +347,7 @@ public DynamoDBRangeKeyAttribute(Type converter) /// Name of attribute to be associated with property or field. /// /// Custom converter type. - public DynamoDBRangeKeyAttribute(string attributeName, Type converter) + public DynamoDBRangeKeyAttribute(string attributeName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] Type converter) : base(attributeName, converter) { } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs index 73f976824695..01a228facd62 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs @@ -22,10 +22,6 @@ namespace Amazon.DynamoDBv2.DataModel /// This should only contain members that are relevant to all object persistence operations, /// anything operation-specific should be added to derived classes. /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public abstract class BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs index 9bfd012824f5..a8fc67184a9e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs @@ -17,6 +17,8 @@ using System.Collections.Generic; using Amazon.DynamoDBv2.DocumentModel; using Amazon.Runtime.Telemetry.Tracing; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; #if AWS_ASYNC_API @@ -59,7 +61,7 @@ public partial interface IBatchGet /// Represents a generic interface for retrieving a batch of items /// from a single DynamoDB table /// - public interface IBatchGet : IBatchGet + public interface IBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : IBatchGet { /// /// List of generic results retrieved from DynamoDB. @@ -127,7 +129,7 @@ public abstract partial class BatchGet : IBatchGet /// Represents a strongly-typed object for retrieving a batch of items /// from a single DynamoDB table /// - public partial class BatchGet : BatchGet, IBatchGet + public partial class BatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : BatchGet, IBatchGet { private readonly DynamoDBContext _context; private readonly DynamoDBFlatConfig _config; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGetConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGetConfig.cs index f7fb57066ee2..220fc4d2a610 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGetConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGetConfig.cs @@ -20,10 +20,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the BatchGet operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class BatchGetConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs index b25cde128e9e..97f4d59d0ce5 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs @@ -18,6 +18,8 @@ using Amazon.DynamoDBv2.DocumentModel; using System.Globalization; using Amazon.Runtime.Telemetry.Tracing; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; #if AWS_ASYNC_API using System.Threading.Tasks; @@ -38,7 +40,8 @@ public partial interface IBatchWrite /// Represents a generic interface for writing/deleting a batch of items /// in a single DynamoDB table /// - public interface IBatchWrite : IBatchWrite + public interface IBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : IBatchWrite + { /// /// Creates a MultiTableBatchWrite object that is a combination @@ -106,7 +109,7 @@ public abstract partial class BatchWrite : IBatchWrite /// Represents a strongly-typed object for writing/deleting a batch of items /// in a single DynamoDB table /// - public partial class BatchWrite : BatchWrite, IBatchWrite + public partial class BatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : BatchWrite, IBatchWrite { private readonly DynamoDBContext _context; private readonly DynamoDBFlatConfig _config; @@ -117,7 +120,7 @@ internal BatchWrite(DynamoDBContext context, DynamoDBFlatConfig config) { } - internal BatchWrite(DynamoDBContext context, Type valuesType, DynamoDBFlatConfig config) + internal BatchWrite(DynamoDBContext context, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType, DynamoDBFlatConfig config) { _context = context; _config = config; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWriteConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWriteConfig.cs index d96bb4bb93e9..d67470261d4c 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWriteConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWriteConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the BatchWrite operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class BatchWriteConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs index 42e52e5b9679..cdc0a536342e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs @@ -48,9 +48,6 @@ public interface IPropertyConverter /// Configuration object for setting options on the that /// will apply to all operations that use the context object. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class DynamoDBContextConfig { /// @@ -150,9 +147,6 @@ public DynamoDBContextConfig() /// This will override any settings specified by the DynamoDBContext's DynamoDBContextConfig object. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class DynamoDBOperationConfig { /// @@ -382,9 +376,6 @@ public QueryCondition(string propertyName, QueryOperator op, params object[] val #endregion } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class DynamoDBFlatConfig { public static string DefaultIndexName = string.Empty; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs index 845b2a9cdd13..37e886672e3a 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs @@ -15,11 +15,14 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading; #if AWS_ASYNC_API using System.Threading.Tasks; + #endif using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -216,21 +219,21 @@ public void Dispose() #region BatchGet /// - public IBatchGet CreateBatchGet() + public IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>() { return CreateBatchGet((BatchGetConfig)null); } /// [Obsolete("Use the CreateBatchGet overload that takes BatchGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")] - public IBatchGet CreateBatchGet(DynamoDBOperationConfig operationConfig) + public IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return new BatchGet(this, config); } /// - public IBatchGet CreateBatchGet(BatchGetConfig batchGetConfig) + public IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(BatchGetConfig batchGetConfig) { return new BatchGet(this, new DynamoDBFlatConfig(batchGetConfig?.ToDynamoDBOperationConfig(), Config)); } @@ -246,41 +249,41 @@ public IMultiTableBatchGet CreateMultiTableBatchGet(params IBatchGet[] batches) #region BatchWrite /// - public IBatchWrite CreateBatchWrite() + public IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>() { return CreateBatchWrite((BatchWriteConfig)null); } /// [Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")] - public IBatchWrite CreateBatchWrite(DynamoDBOperationConfig operationConfig) + public IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return new BatchWrite(this, config); } /// - public IBatchWrite CreateBatchWrite(Type valuesType) + public IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType) { return CreateBatchWrite(valuesType, (BatchWriteConfig)null); } /// [Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")] - public IBatchWrite CreateBatchWrite(Type valuesType, DynamoDBOperationConfig operationConfig) + public IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return new BatchWrite(this, valuesType, config); } /// - public IBatchWrite CreateBatchWrite(BatchWriteConfig batchWriteConfig) + public IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(BatchWriteConfig batchWriteConfig) { return new BatchWrite(this, new DynamoDBFlatConfig(batchWriteConfig?.ToDynamoDBOperationConfig(), Config)); } /// - public IBatchWrite CreateBatchWrite(Type valuesType, BatchWriteConfig batchWriteConfig) + public IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType, BatchWriteConfig batchWriteConfig) { return new BatchWrite(this, valuesType, new DynamoDBFlatConfig(batchWriteConfig.ToDynamoDBOperationConfig(), Config)); } @@ -296,21 +299,21 @@ public IMultiTableBatchWrite CreateMultiTableBatchWrite(params IBatchWrite[] bat #region TransactGet /// - public ITransactGet CreateTransactGet() + public ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>() { return CreateTransactGet((TransactGetConfig)null); } /// [Obsolete("Use the CreateTransactGet overload that takes TransactGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")] - public ITransactGet CreateTransactGet(DynamoDBOperationConfig operationConfig) + public ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return new TransactGet(this, config); } /// - public ITransactGet CreateTransactGet(TransactGetConfig transactGetConfig) + public ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(TransactGetConfig transactGetConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(transactGetConfig?.ToDynamoDBOperationConfig(), this.Config); return new TransactGet(this, config); @@ -327,7 +330,7 @@ public IMultiTableTransactGet CreateMultiTableTransactGet(params ITransactGet[] #region TransactWrite /// - public ITransactWrite CreateTransactWrite() + public ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>() { return CreateTransactWrite((TransactWriteConfig)null); } @@ -335,14 +338,14 @@ public ITransactWrite CreateTransactWrite() /// [Obsolete("Use the CreateTransactWrite overload that takes TransactWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to CreateTransactWrite.")] - public ITransactWrite CreateTransactWrite(DynamoDBOperationConfig operationConfig) + public ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); return new TransactWrite(this, config); } /// - public ITransactWrite CreateTransactWrite(TransactWriteConfig transactWriteConfig) + public ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(TransactWriteConfig transactWriteConfig) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(transactWriteConfig?.ToDynamoDBOperationConfig(), this.Config); return new TransactWrite(this, config); @@ -358,7 +361,7 @@ public IMultiTableTransactWrite CreateMultiTableTransactWrite(params ITransactWr #region Save/serialize - private void SaveHelper(T value, DynamoDBFlatConfig flatConfig) + private void SaveHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBFlatConfig flatConfig) { if (value == null) return; @@ -385,12 +388,12 @@ private void SaveHelper(T value, DynamoDBFlatConfig flatConfig) } #if AWS_ASYNC_API - private async Task SaveHelperAsync(T value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) + private async Task SaveHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { await SaveHelperAsync(typeof(T), value, flatConfig, cancellationToken).ConfigureAwait(false); } - private async Task SaveHelperAsync(Type valueType, object value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) + private async Task SaveHelperAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { if (value == null) return; @@ -419,14 +422,14 @@ await table.UpdateHelperAsync( #endif /// - public Document ToDocument(T value) + public Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value) { return ToDocument(value, (ToDocumentConfig)null); } /// [Obsolete("Use the ToDocument overload that takes ToDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ToDocument.")] - public Document ToDocument(T value, DynamoDBOperationConfig operationConfig) + public Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig) { if (value == null) return null; @@ -438,7 +441,7 @@ public Document ToDocument(T value, DynamoDBOperationConfig operationConfig) } /// - public Document ToDocument(T value, ToDocumentConfig toDocumentConfig) + public Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, ToDocumentConfig toDocumentConfig) { if (value == null) return null; @@ -453,15 +456,15 @@ public Document ToDocument(T value, ToDocumentConfig toDocumentConfig) #region Load/deserialize - private T LoadHelper(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig) + private T LoadHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig); return LoadHelper(key, flatConfig, storageConfig); } -#if AWS_ASYNC_API - private Task LoadHelperAsync(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) +#if AWS_ASYNC_API + private Task LoadHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig); @@ -469,15 +472,16 @@ private Task LoadHelperAsync(object hashKey, object rangeKey, DynamoDBFlat } #endif - private T LoadHelper(T keyObject, DynamoDBFlatConfig flatConfig) + private T LoadHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(keyObject, storageConfig, flatConfig); return LoadHelper(key, flatConfig, storageConfig); } -#if AWS_ASYNC_API - private Task LoadHelperAsync(T keyObject, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) +#if AWS_ASYNC_API + + private Task LoadHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(keyObject, storageConfig, flatConfig); @@ -485,7 +489,7 @@ private Task LoadHelperAsync(T keyObject, DynamoDBFlatConfig flatConfig, C } #endif - private T LoadHelper(Key key, DynamoDBFlatConfig flatConfig, ItemStorageConfig storageConfig) + private T LoadHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Key key, DynamoDBFlatConfig flatConfig, ItemStorageConfig storageConfig) { GetItemOperationConfig getConfig = new GetItemOperationConfig { @@ -501,8 +505,9 @@ private T LoadHelper(Key key, DynamoDBFlatConfig flatConfig, ItemStorageConfi return instance; } -#if AWS_ASYNC_API - private async Task LoadHelperAsync(Key key, DynamoDBFlatConfig flatConfig, ItemStorageConfig storageConfig, CancellationToken cancellationToken) +#if AWS_ASYNC_API + + private async Task LoadHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Key key, DynamoDBFlatConfig flatConfig, ItemStorageConfig storageConfig, CancellationToken cancellationToken) { GetItemOperationConfig getConfig = new GetItemOperationConfig { @@ -520,27 +525,27 @@ private async Task LoadHelperAsync(Key key, DynamoDBFlatConfig flatConfig, #endif /// - public T FromDocument(Document document) + public T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document) { return FromDocument(document, (FromDocumentConfig)null); } /// [Obsolete("Use the FromDocument overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocument.")] - public T FromDocument(Document document, DynamoDBOperationConfig operationConfig) + public T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); return FromDocumentHelper(document, flatConfig); } /// - public T FromDocument(Document document, FromDocumentConfig fromDocumentConfig) + public T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document, FromDocumentConfig fromDocumentConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(fromDocumentConfig?.ToDynamoDBOperationConfig(), Config); return FromDocumentHelper(document, flatConfig); } - internal T FromDocumentHelper(Document document, DynamoDBFlatConfig flatConfig) + internal T FromDocumentHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); ItemStorage storage = new ItemStorage(storageConfig); @@ -550,14 +555,14 @@ internal T FromDocumentHelper(Document document, DynamoDBFlatConfig flatConfi } /// - public IEnumerable FromDocuments(IEnumerable documents) + public IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents) { return FromDocuments(documents, (FromDocumentConfig)null); } /// [Obsolete("Use the FromDocuments overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocuments.")] - public IEnumerable FromDocuments(IEnumerable documents, DynamoDBOperationConfig operationConfig) + public IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents, DynamoDBOperationConfig operationConfig) { foreach (var document in documents) { @@ -567,7 +572,7 @@ public IEnumerable FromDocuments(IEnumerable documents, DynamoDB } /// - public IEnumerable FromDocuments(IEnumerable documents, FromDocumentConfig fromDocumentConfig) + public IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents, FromDocumentConfig fromDocumentConfig) { foreach (var document in documents) { @@ -576,7 +581,7 @@ public IEnumerable FromDocuments(IEnumerable documents, FromDocu } } - internal IEnumerable FromDocumentsHelper(IEnumerable documents, DynamoDBFlatConfig flatConfig) + internal IEnumerable FromDocumentsHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents, DynamoDBFlatConfig flatConfig) { foreach (var document in documents) { @@ -589,7 +594,7 @@ internal IEnumerable FromDocumentsHelper(IEnumerable documents, #region Delete - private void DeleteHelper(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig) + private void DeleteHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig); @@ -598,8 +603,8 @@ private void DeleteHelper(object hashKey, object rangeKey, DynamoDBFlatConfig table.DeleteHelper(key, null); } -#if AWS_ASYNC_API - private Task DeleteHelperAsync(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) +#if AWS_ASYNC_API + private Task DeleteHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig); @@ -609,7 +614,7 @@ private Task DeleteHelperAsync(object hashKey, object rangeKey, DynamoDBFlatC } #endif - private void DeleteHelper(T value, DynamoDBFlatConfig flatConfig) + private void DeleteHelper<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBFlatConfig flatConfig) { if (value == null) throw new ArgumentNullException("value"); @@ -635,7 +640,7 @@ private void DeleteHelper(T value, DynamoDBFlatConfig flatConfig) private static readonly Task CompletedTask = Task.FromResult(null); - private Task DeleteHelperAsync(T value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) + private Task DeleteHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBFlatConfig flatConfig, CancellationToken cancellationToken) { if (value == null) throw new ArgumentNullException("value"); diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextBuilder.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextBuilder.cs index 0ffe72e69eed..9f288f62e067 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextBuilder.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextBuilder.cs @@ -18,9 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel { /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class DynamoDBContextBuilder : IDynamoDBContextBuilder { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs index 32c771e11a06..781292ac6845 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs @@ -25,12 +25,11 @@ using Amazon.Util.Internal; using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public partial class DynamoDBContext { #region Versioning @@ -121,7 +120,7 @@ internal static Expression CreateConditionExpressionForVersion(ItemStorage stora #region Table methods // Retrieves the target table for the specified type - private Table GetTargetTableInternal(DynamoDBFlatConfig flatConfig) + private Table GetTargetTableInternal<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBFlatConfig flatConfig) { Type type = typeof(T); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(type, flatConfig); @@ -338,12 +337,13 @@ private static bool ShouldSave(DynamoDBEntry entry, bool ignoreNullValues) /// /// Deserializes a DynamoDB document to an object /// - private T DocumentToObject(ItemStorage storage, DynamoDBFlatConfig flatConfig) + private T DocumentToObject<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ItemStorage storage, DynamoDBFlatConfig flatConfig) { Type type = typeof(T); return (T)DocumentToObject(type, storage, flatConfig); } - private object DocumentToObject(Type objectType, ItemStorage storage, DynamoDBFlatConfig flatConfig) + + private object DocumentToObject([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type objectType, ItemStorage storage, DynamoDBFlatConfig flatConfig) { if (storage == null) throw new ArgumentNullException("storage"); @@ -401,7 +401,7 @@ private void PopulateInstance(ItemStorage storage, object instance, DynamoDBFlat /// /// Serializes an object into a DynamoDB document /// - private ItemStorage ObjectToItemStorage(T toStore, bool keysOnly, DynamoDBFlatConfig flatConfig) + private ItemStorage ObjectToItemStorage<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T toStore, bool keysOnly, DynamoDBFlatConfig flatConfig) { if (toStore == null) return null; @@ -409,7 +409,7 @@ private ItemStorage ObjectToItemStorage(T toStore, bool keysOnly, DynamoDBFla return ObjectToItemStorage(toStore, objectType, keysOnly, flatConfig); } - private ItemStorage ObjectToItemStorage(object toStore, Type objectType, bool keysOnly, DynamoDBFlatConfig flatConfig) + private ItemStorage ObjectToItemStorage(object toStore, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type objectType, bool keysOnly, DynamoDBFlatConfig flatConfig) { ItemStorageConfig config = StorageConfigCache.GetConfig(objectType, flatConfig); ItemStorage storage = ObjectToItemStorageHelper(toStore, config, flatConfig, keysOnly, flatConfig.IgnoreNullValues.Value); @@ -517,14 +517,18 @@ private object FromDynamoDBEntry(SimplePropertyStorage propertyStorage, DynamoDB entry, entry.GetType().FullName, propertyStorage.PropertyName, propertyStorage.MemberType.FullName)); } } - private bool TryFromList(Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) + + private bool TryFromList([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) { return targetType.IsArray ? TryFromListToArray(targetType, list, flatConfig, out output) : //targetType is Array TryFromListToIList(targetType, list, flatConfig, out output) ; //targetType is IList or has Add method. } - private bool TryFromListToIList(Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062", + Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed.")] + + private bool TryFromListToIList([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) { if ((!Utils.ImplementsInterface(targetType, typeof(ICollection<>)) && !Utils.ImplementsInterface(targetType, typeof(IList))) || @@ -560,7 +564,7 @@ private bool TryFromListToIList(Type targetType, DynamoDBList list, DynamoDBFlat return true; } - private bool TryFromListToArray(Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) + private bool TryFromListToArray([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType, DynamoDBList list, DynamoDBFlatConfig flatConfig, out object output) { if (!Utils.CanInstantiateArray(targetType)) { @@ -584,7 +588,9 @@ private bool TryFromListToArray(Type targetType, DynamoDBList list, DynamoDBFlat return true; } - private bool TryFromMap(Type targetType, Document map, DynamoDBFlatConfig flatConfig, out object output) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067", + Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed.")] + private bool TryFromMap([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType, Document map, DynamoDBFlatConfig flatConfig, out object output) { output = null; @@ -655,7 +661,10 @@ private DynamoDBEntry ToDynamoDBEntry(SimplePropertyStorage propertyStorage, obj return SerializeToDocument(value, type, flatConfig); } } - private bool TryToMap(object value, Type type, DynamoDBFlatConfig flatConfig, out Document output) + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067", + Justification = "The user's type has been annotated with InternalConstants.DataModelModeledType with the public API into the library. At this point the type will not be trimmed.")] + private bool TryToMap(object value, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type, DynamoDBFlatConfig flatConfig, out Document output) { output = null; @@ -687,7 +696,8 @@ private bool TryToMap(object value, Type type, DynamoDBFlatConfig flatConfig, ou } return true; } - private bool TryToList(object value, Type type, DynamoDBFlatConfig flatConfig, out DynamoDBList output) + + private bool TryToList(object value, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, DynamoDBFlatConfig flatConfig, out DynamoDBList output) { if (!Utils.ImplementsInterface(type, typeof(ICollection<>))) { @@ -754,12 +764,13 @@ private bool TryToScalar(object value, Type type, DynamoDBFlatConfig flatConfig, return false; } - private static bool IsSupportedDictionaryType(Type type, out Type valueType) + private static bool IsSupportedDictionaryType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, out Type valueType) { Type keyType; return IsSupportedDictionaryType(type, out keyType, out valueType); } - private static bool IsSupportedDictionaryType(Type type, out Type keyType, out Type valueType) + + private static bool IsSupportedDictionaryType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, out Type keyType, out Type valueType) { keyType = valueType = null; @@ -783,7 +794,7 @@ private static bool IsSupportedDictionaryType(Type type, out Type keyType, out T /// Deserializes a given Document to instance of targetType /// Use only for property conversions, not for full item conversion /// - private object DeserializeFromDocument(Document document, Type targetType, DynamoDBFlatConfig flatConfig) + private object DeserializeFromDocument(Document document, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(targetType, flatConfig, conversionOnly: true); ItemStorage storage = new ItemStorage(storageConfig); @@ -796,7 +807,7 @@ private object DeserializeFromDocument(Document document, Type targetType, Dynam /// Serializes a given value to Document /// Use only for property conversions, not for full item conversion /// - private Document SerializeToDocument(object value, Type type, DynamoDBFlatConfig flatConfig) + private Document SerializeToDocument(object value, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type, DynamoDBFlatConfig flatConfig) { ItemStorageConfig config = StorageConfigCache.GetConfig(type, flatConfig, conversionOnly: true); var itemStorage = ObjectToItemStorageHelper(value, config, flatConfig, keysOnly: false, ignoreNullValues: flatConfig.IgnoreNullValues.Value); @@ -1141,7 +1152,8 @@ public ContextSearch(Search search, DynamoDBFlatConfig flatConfig) FlatConfig = flatConfig; } } - private IEnumerable FromSearch(ContextSearch cs) + + private IEnumerable FromSearch<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ContextSearch cs) { if (cs == null) throw new ArgumentNullException("cs"); @@ -1169,7 +1181,7 @@ private IEnumerable FromSearch(ContextSearch cs) #region Scan/Query - private ContextSearch ConvertScan(IEnumerable conditions, DynamoDBOperationConfig operationConfig) + private ContextSearch ConvertScan<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); @@ -1191,7 +1203,7 @@ private ContextSearch ConvertScan(IEnumerable conditions, Dyna return new ContextSearch(scan, flatConfig); } - private ContextSearch ConvertFromScan(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig) + private ContextSearch ConvertFromScan<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); @@ -1202,7 +1214,7 @@ private ContextSearch ConvertFromScan(ScanOperationConfig scanConfig, DynamoD return new ContextSearch(search, flatConfig); } - private ContextSearch ConvertFromQuery(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig) + private ContextSearch ConvertFromQuery<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); @@ -1213,7 +1225,7 @@ private ContextSearch ConvertFromQuery(QueryOperationConfig queryConfig, Dyna return new ContextSearch(search, flatConfig); } - private ContextSearch ConvertQueryByValue(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig) + private ContextSearch ConvertQueryByValue<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(flatConfig); @@ -1222,7 +1234,7 @@ private ContextSearch ConvertQueryByValue(object hashKeyValue, QueryOperator return query; } - private ContextSearch ConvertQueryByValue(object hashKeyValue, IEnumerable conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null) + private ContextSearch ConvertQueryByValue<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, IEnumerable conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); if (storageConfig == null) @@ -1232,6 +1244,7 @@ private ContextSearch ConvertQueryByValue(object hashKeyValue, IEnumerable(flatConfig, storageConfig, filter, indexNames); } + private ContextSearch ConvertQueryHelper(DynamoDBFlatConfig currentConfig, ItemStorageConfig storageConfig, QueryFilter filter, List indexNames) { Table table = GetTargetTable(storageConfig, currentConfig); @@ -1261,7 +1274,7 @@ private ContextSearch ConvertQueryHelper(DynamoDBFlatConfig currentConfig, It return new ContextSearch(query, currentConfig); } - private AsyncSearch FromSearchAsync(ContextSearch contextSearch) + private AsyncSearch FromSearchAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ContextSearch contextSearch) { return new AsyncSearch(this, contextSearch); } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/DeleteConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/DeleteConfig.cs index 4064195cd5cc..4d4fe3748788 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/DeleteConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/DeleteConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the Delete operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class DeleteConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromDocumentConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromDocumentConfig.cs index 454ebeb2aaa2..4e70c90c5289 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromDocumentConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromDocumentConfig.cs @@ -20,10 +20,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the FromDocument operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class FromDocumentConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromQueryConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromQueryConfig.cs index 8b1c1d418648..a9ddd37dcaed 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromQueryConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromQueryConfig.cs @@ -22,10 +22,6 @@ namespace Amazon.DynamoDBv2.DataModel /// Additional input for the FromQuery operation in the object-persistence programming model. This supplements /// , which is shared between the document and object-persistence models. /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class FromQueryConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromScanConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromScanConfig.cs index fde94a66ccbd..4fb3aef69a60 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromScanConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/FromScanConfig.cs @@ -23,10 +23,6 @@ namespace Amazon.DynamoDBv2.DataModel /// Additional input for the FromScan operation in the object-persistence programming model. This supplements /// , which is shared between the document and object-persistence models. /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class FromScanConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/GetTargetTableConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/GetTargetTableConfig.cs index 795ed6020c09..65efe471331f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/GetTargetTableConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/GetTargetTableConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the GetTargetTable operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class GetTargetTableConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs index c9941d2bc5b4..3b7058cd0f75 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/IDynamoDBContext.cs @@ -15,8 +15,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -51,8 +53,7 @@ public partial interface IDynamoDBContext : IDisposable /// Type to serialize as. /// Object to serialize. /// with attributes populated from object. - Document ToDocument(T value); - + Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value); /// /// Serializes an object to a . /// @@ -61,7 +62,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override the table used. /// with attributes populated from object. [Obsolete("Use the ToDocument overload that takes ToDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ToDocument.")] - Document ToDocument(T value, DynamoDBOperationConfig operationConfig); + Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig); /// /// Serializes an object to a . @@ -70,7 +71,7 @@ public partial interface IDynamoDBContext : IDisposable /// Object to serialize. /// Config object that can be used to override properties on the table's context for this request. /// with attributes populated from object. - Document ToDocument(T value, ToDocumentConfig toDocumentConfig); + Document ToDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, ToDocumentConfig toDocumentConfig); #endregion @@ -84,7 +85,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Object of type T, populated with properties from the document. /// - T FromDocument(Document document); + T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document); /// /// Deserializes a to an instance of type T. @@ -96,8 +97,8 @@ public partial interface IDynamoDBContext : IDisposable /// Object of type T, populated with properties from the document. /// [Obsolete("Use the FromDocument overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocument.")] + T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document, DynamoDBOperationConfig operationConfig); - T FromDocument(Document document, DynamoDBOperationConfig operationConfig); /// /// Deserializes a to an instance of type T. @@ -108,7 +109,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Object of type T, populated with properties from the document. /// - T FromDocument(Document document, FromDocumentConfig fromDocumentConfig); + T FromDocument<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(Document document, FromDocumentConfig fromDocumentConfig); /// /// Deserializes a collections of documents to a collection of instances of type T. @@ -118,7 +119,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Collection of items of type T, each populated with properties from a corresponding document. /// - IEnumerable FromDocuments(IEnumerable documents); + IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents); /// /// Deserializes a collections of documents to a collection of instances of type T. @@ -130,7 +131,7 @@ public partial interface IDynamoDBContext : IDisposable /// Collection of items of type T, each populated with properties from a corresponding document. /// [Obsolete("Use the FromDocuments overload that takes FromDocumentConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromDocuments.")] - IEnumerable FromDocuments(IEnumerable documents, DynamoDBOperationConfig operationConfig); + IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents, DynamoDBOperationConfig operationConfig); /// /// Deserializes a collections of documents to a collection of instances of type T. @@ -141,7 +142,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Collection of items of type T, each populated with properties from a corresponding document. /// - IEnumerable FromDocuments(IEnumerable documents, FromDocumentConfig fromDocumentConfig); + IEnumerable FromDocuments<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable documents, FromDocumentConfig fromDocumentConfig); #endregion @@ -153,7 +154,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Type of objects to get /// Empty strongly-typed BatchGet object - IBatchGet CreateBatchGet(); + IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(); /// /// Creates a strongly-typed BatchGet object, allowing @@ -163,7 +164,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override that table used. /// A BatchGet object using this context's configuration, which can be used to prepare and execute a BatchGet request [Obsolete("Use the CreateBatchGet overload that takes BatchGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")] - IBatchGet CreateBatchGet(DynamoDBOperationConfig operationConfig = null); + IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null); /// /// Creates a strongly-typed BatchGet object, allowing @@ -172,7 +173,7 @@ public partial interface IDynamoDBContext : IDisposable /// Type of objects to get /// Config object that can be used to override properties on the table's context for this request /// A BatchGet object based on the provided , which can be used to prepare and execute a BatchGet request - IBatchGet CreateBatchGet(BatchGetConfig batchGetConfig); + IBatchGet CreateBatchGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(BatchGetConfig batchGetConfig); /// /// Creates a MultiTableBatchGet object, composed of multiple @@ -192,7 +193,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Type of objects to write /// Empty strongly-typed BatchWrite object - IBatchWrite CreateBatchWrite(); + IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(); /// /// Creates a strongly-typed BatchWrite object, allowing @@ -202,8 +203,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override that table used. /// Empty strongly-typed BatchWrite object [Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")] - - IBatchWrite CreateBatchWrite(DynamoDBOperationConfig operationConfig = null); + IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null); /// /// Creates a strongly-typed BatchWrite object, allowing @@ -217,7 +217,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// The type of data which will be persisted in this batch. /// Empty strongly-typed BatchWrite object - IBatchWrite CreateBatchWrite(Type valuesType); + IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType); /// /// Creates a strongly-typed BatchWrite object, allowing @@ -233,7 +233,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override that table used. /// Empty strongly-typed BatchWrite object [Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")] - IBatchWrite CreateBatchWrite(Type valuesType, DynamoDBOperationConfig operationConfig = null); + IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType, DynamoDBOperationConfig operationConfig = null); /// /// Creates a strongly-typed BatchWrite object, allowing @@ -242,7 +242,7 @@ public partial interface IDynamoDBContext : IDisposable /// Type of objects to write /// Config object that can be used to override properties on the table's context for this request. /// Empty strongly-typed BatchWrite object - IBatchWrite CreateBatchWrite(BatchWriteConfig batchWriteConfig); + IBatchWrite CreateBatchWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(BatchWriteConfig batchWriteConfig); /// /// Creates a strongly-typed BatchWrite object, allowing @@ -257,7 +257,7 @@ public partial interface IDynamoDBContext : IDisposable /// The type of data which will be persisted in this batch. /// Config object that can be used to override properties on the table's context for this request. /// Empty strongly-typed BatchWrite object - IBatchWrite CreateBatchWrite(Type valuesType, BatchWriteConfig batchWriteConfig); + IBatchWrite CreateBatchWrite([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valuesType, BatchWriteConfig batchWriteConfig); /// /// Creates a MultiTableBatchWrite object, composed of multiple @@ -277,7 +277,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Type of objects to get. /// Empty strongly-typed TransactGet object. - ITransactGet CreateTransactGet(); + ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(); /// /// Creates a strongly-typed TransactGet object, allowing @@ -287,7 +287,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override that table used. /// Empty strongly-typed TransactGet object. [Obsolete("Use the CreateTransactGet overload that takes TransactGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")] - ITransactGet CreateTransactGet(DynamoDBOperationConfig operationConfig = null); + ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null); /// /// Creates a strongly-typed TransactGet object, allowing @@ -296,7 +296,7 @@ public partial interface IDynamoDBContext : IDisposable /// Type of objects to get. /// Config object that can be used to override properties on the table's context for this request. /// Empty strongly-typed TransactGet object. - ITransactGet CreateTransactGet(TransactGetConfig transactGetConfig); + ITransactGet CreateTransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(TransactGetConfig transactGetConfig); /// /// Creates a MultiTableTransactGet object, composed of multiple @@ -316,7 +316,7 @@ public partial interface IDynamoDBContext : IDisposable /// /// Type of objects to write. /// Empty strongly-typed TransactWrite object. - ITransactWrite CreateTransactWrite(); + ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(); /// /// Creates a strongly-typed TransactWrite object, allowing @@ -326,7 +326,7 @@ public partial interface IDynamoDBContext : IDisposable /// Config object which can be used to override that table used. /// Empty strongly-typed TransactWrite object. [Obsolete("Use the CreateTransactWrite overload that takes TransactWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to CreateTransactWrite.")] - ITransactWrite CreateTransactWrite(DynamoDBOperationConfig operationConfig = null); + ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null); /// /// Creates a strongly-typed TransactWrite object, allowing @@ -335,7 +335,7 @@ public partial interface IDynamoDBContext : IDisposable /// Type of objects to write. /// Config object that can be used to override properties on the table's context for this request. /// Empty strongly-typed TransactWrite object. - ITransactWrite CreateTransactWrite(TransactWriteConfig transactWriteConfig); + ITransactWrite CreateTransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(TransactWriteConfig transactWriteConfig); /// /// Creates a MultiTableTransactWrite object, composed of multiple diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs index 525b85c51046..f17d01c5ed2f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs @@ -30,15 +30,13 @@ using Amazon.Runtime.Internal.Util; using Amazon.Util; using Amazon.Util.Internal; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { /// /// Basic property storage information /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class SimplePropertyStorage { // local property name @@ -50,22 +48,25 @@ internal class SimplePropertyStorage public MemberInfo Member { get; protected set; } // Type of the property -#if NET8_0_OR_GREATER - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] -#endif + [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] public Type MemberType { get; protected set; } // Converter type, if one is present + + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] public Type ConverterType { get; set; } // Converter, if one is present public IPropertyConverter Converter { get; protected set; } - public SimplePropertyStorage(MemberInfo member) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072", + Justification = "The user's type has been annotated with DynamicallyAccessedMemberTypes.All with the public API into the library. At this point the type will not be trimmed.")] + internal SimplePropertyStorage(MemberInfo member) : this(Utils.GetType(member)) { Member = member; PropertyName = member.Name; } - public SimplePropertyStorage(Type memberType) + + public SimplePropertyStorage([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)]Type memberType) { MemberType = memberType; } @@ -80,9 +81,6 @@ public override string ToString() /// /// DynamoDB property storage information /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class PropertyStorage : SimplePropertyStorage { // flags @@ -188,7 +186,9 @@ public void Validate(DynamoDBContext context) IndexNames.AddRange(index.IndexNames); } - public PropertyStorage(MemberInfo member) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + Justification = "The user's type has been annotated with DynamicallyAccessedMemberTypes.All with the public API into the library. At this point the type will not be trimmed.")] + internal PropertyStorage(MemberInfo member) : base(member) { IndexNames = new List(); @@ -199,9 +199,6 @@ public PropertyStorage(MemberInfo member) /// /// Storage information for a single item /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class ItemStorage { public Document Document { get; set; } @@ -238,9 +235,6 @@ public GSIConfig(string indexName) /// /// Storage information for a specific class /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class StorageConfig { // normalized PropertyStorage objects @@ -310,7 +304,7 @@ private bool FindSingleProperty(Func match, string errorM throw new InvalidOperationException(errorMessage); } - private static Dictionary GetMembersDictionary(Type type) + private static Dictionary GetMembersDictionary([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type) { Dictionary dictionary = new Dictionary(StringComparer.Ordinal); @@ -324,9 +318,10 @@ private static Dictionary GetMembersDictionary(Type type) return dictionary; } - + + // constructor - public StorageConfig(Type targetType) + internal StorageConfig([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType) { if (!Utils.CanInstantiate(targetType)) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, @@ -346,9 +341,6 @@ public StorageConfig(Type targetType) /// /// Storage information for a specific class that is associated with a table /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class ItemStorageConfig : StorageConfig { // table @@ -558,7 +550,7 @@ private void AddGSIConfigs(List gsiIndexNames, string propertyName, bool // constructor - public ItemStorageConfig(Type targetType) + internal ItemStorageConfig([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType) : base(targetType) { AttributeToIndexesNameMapping = new Dictionary>(StringComparer.Ordinal); @@ -575,9 +567,6 @@ public ItemStorageConfig(Type targetType) /// /// Cache of ItemStorageConfig objects /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class ItemStorageConfigCache : IDisposable { // Cache of ItemStorageConfig objects per table and the @@ -607,12 +596,13 @@ public ItemStorageConfigCache(DynamoDBContext context) Context = context; } - public ItemStorageConfig GetConfig(DynamoDBFlatConfig flatConfig, bool conversionOnly = false) + public ItemStorageConfig GetConfig<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBFlatConfig flatConfig, bool conversionOnly = false) { Type type = typeof(T); return GetConfig(type, flatConfig, conversionOnly); } - public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig, bool conversionOnly = false) + + public ItemStorageConfig GetConfig([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type, DynamoDBFlatConfig flatConfig, bool conversionOnly = false) { ConfigTableCache tableCache = null; ItemStorageConfig config; @@ -697,7 +687,7 @@ private static string GetAccurateCase(ItemStorageConfig config, string value) return (config.LowerCamelCaseProperties ? Utils.ToLowerCamelCase(value) : value); } - private ItemStorageConfig CreateStorageConfig(Type baseType, string actualTableName, DynamoDBFlatConfig flatConfig) + private ItemStorageConfig CreateStorageConfig([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type baseType, string actualTableName, DynamoDBFlatConfig flatConfig) { if (baseType == null) throw new ArgumentNullException("baseType"); @@ -745,7 +735,7 @@ private ItemStorageConfig CreateStorageConfig(Type baseType, string actualTableN return config; } - private static void PopulateConfigFromType(ItemStorageConfig config, Type type) + private static void PopulateConfigFromType(ItemStorageConfig config, [DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type) { DynamoDBTableAttribute tableAttribute = Utils.GetTableAttribute(type); if (tableAttribute == null) diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/LoadConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/LoadConfig.cs index 9ca0f36e837e..e63bc6ed15bd 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/LoadConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/LoadConfig.cs @@ -20,10 +20,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the Load operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class LoadConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/QueryConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/QueryConfig.cs index 25fe58ce454f..46d28c5566ce 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/QueryConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/QueryConfig.cs @@ -22,10 +22,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the Query operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class QueryConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3ClientCache.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3ClientCache.cs index 76ffdfb092fe..6e72f3faf6c0 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3ClientCache.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3ClientCache.cs @@ -1,17 +1,20 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using Amazon.Runtime; using Amazon.Runtime.Internal; +using Amazon.Runtime.Internal.Util; using Amazon.Runtime.SharedInterfaces; +using Amazon.RuntimeDependencies; +using Amazon.Util.Internal; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class S3ClientCache { private AmazonDynamoDBClient ddbClient; @@ -34,12 +37,38 @@ internal void UseClient(ICoreAmazonS3 client, RegionEndpoint region) this.clientsByRegion.Add(region.SystemName, client); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", + Justification = "Reflection code is only used as a fallback in case the SDK was not trimmed. Trimmed scenarios should register dependencies with Amazon.RuntimeDependencyRegistry.GlobalRuntimeDependencyRegistry")] internal ICoreAmazonS3 GetClient(RegionEndpoint region) { ICoreAmazonS3 output; + if (!this.clientsByRegion.TryGetValue(region.SystemName, out output)) { - output = ServiceClientHelpers.CreateServiceFromAssembly(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, this.ddbClient); + output = GlobalRuntimeDependencyRegistry.Instance.GetInstance(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, + new CreateInstanceContext(new S3ClientContext { Action = S3ClientContext.ActionContext.DynamoBDS3Link, Region = region })); + + if (output == null) + { + try + { + output = ServiceClientHelpers.CreateServiceFromAssembly(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, this.ddbClient); + } + catch (Exception e) + { + if (InternalSDKUtils.IsRunningNativeAot()) + { + throw new MissingRuntimeDependencyException(ServiceClientHelpers.S3_ASSEMBLY_NAME, ServiceClientHelpers.S3_SERVICE_CLASS_NAME, nameof(GlobalRuntimeDependencyRegistry.RegisterS3Client)); + } + + var msg = string.Format(CultureInfo.CurrentCulture, + "Assembly {0} could not be found or loaded. This assembly must be available at runtime to use the DynamoDB feature S3 Link.", + ServiceClientHelpers.S3_ASSEMBLY_NAME); + var exception = new InvalidOperationException(msg, e); + Logger.GetLogger(typeof(S3ClientCache)).Error(exception, exception.Message); + throw exception; + } + } this.clientsByRegion.Add(region.SystemName, output); } return output; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3Link.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3Link.cs index 7028d8c282a3..ed72236c8fda 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3Link.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/S3Link.cs @@ -1,20 +1,21 @@ using Amazon.DynamoDBv2.DocumentModel; using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; +using Amazon.Util.Internal; using ThirdParty.Json.LitJson; +#if NET8_0_OR_GREATER +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; +#endif + namespace Amazon.DynamoDBv2.DataModel { /// /// S3Link is an object that provides a connection to an S3 resource /// that can be stored in a DynamoDB field through DynamoDBContext /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public partial class S3Link { #region Statics @@ -159,12 +160,12 @@ internal S3Link(S3ClientCache clientCache, string json) if (clientCache == null) throw new ArgumentNullException("clientCache"); if (json == null) throw new ArgumentNullException("json"); this.s3ClientCache = clientCache; - linker = JsonMapper.ToObject(json); + linker = JsonSerializerHelper.Deserialize(json, S3LinkInfoJsonSerializerContexts.Default); } internal static RegionEndpoint GetRegionFromJSON(string json) { - var linker = JsonMapper.ToObject(json); + var linker = JsonSerializerHelper.Deserialize(json, S3LinkInfoJsonSerializerContexts.Default); if (linker.s3.region == null) { return RegionEndpoint.GetBySystemName("us-east-1"); @@ -208,7 +209,7 @@ public string GetPreSignedURL(DateTime expiration) internal string ToJson() { - return JsonMapper.ToJson(linker); + return JsonSerializerHelper.Serialize(linker, S3LinkInfoJsonSerializerContexts.Default); } #endregion @@ -216,9 +217,6 @@ internal string ToJson() #endregion #region Helper Classes -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif internal class S3LinkConverter : IPropertyConverter { @@ -246,7 +244,7 @@ public object FromEntry(DocumentModel.DynamoDBEntry entry) } } - private class LinkInfo + internal class LinkInfo { public S3 s3 { get; set; } @@ -268,7 +266,7 @@ public LinkInfo(string bucketName, string key, string region) } } - private class S3 + internal class S3 { public string bucket { get; set; } public string key { get; set; } @@ -291,5 +289,9 @@ public S3(string bucketName, string key, string region) #endregion + [JsonSerializable(typeof(LinkInfo))] + internal partial class S3LinkInfoJsonSerializerContexts : JsonSerializerContext + { + } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/SaveConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/SaveConfig.cs index 5592a43c3531..1cd9640df384 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/SaveConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/SaveConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the Save operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class SaveConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ScanConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ScanConfig.cs index 53e2929eab58..7f4536f25771 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ScanConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ScanConfig.cs @@ -22,10 +22,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the Scan operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class ScanConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ToDocumentConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ToDocumentConfig.cs index be24bac29255..da61a2a09062 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/ToDocumentConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/ToDocumentConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the ToDocument operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class ToDocumentConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs index ae4e15bb06be..09268d05f0dd 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs @@ -15,12 +15,16 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + #if AWS_ASYNC_API using System.Threading; using System.Threading.Tasks; + #endif using Amazon.DynamoDBv2.DocumentModel; using Amazon.Runtime.Telemetry.Tracing; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -43,7 +47,7 @@ public partial interface ITransactGet /// Represents a generic interface for retrieving multiple items /// from a single DynamoDB table in a transaction. /// - public interface ITransactGet : ITransactGet + public interface ITransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : ITransactGet { /// /// List of generic results retrieved from DynamoDB. @@ -110,7 +114,8 @@ public abstract partial class TransactGet : ITransactGet /// Represents a strongly-typed object for retrieving multiple items /// from a single DynamoDB table in a transaction. /// - public partial class TransactGet : TransactGet, ITransactGet + public partial class TransactGet<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : TransactGet, ITransactGet + { private readonly DynamoDBContext _context; private readonly DynamoDBFlatConfig _config; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGetConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGetConfig.cs index 2b4749a46081..d0bb2112ff26 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGetConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGetConfig.cs @@ -20,10 +20,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the TransactGet operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class TransactGetConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs index bff1eb006727..d521a79bbd7e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs @@ -15,13 +15,16 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; #if AWS_ASYNC_API using System.Threading; using System.Threading.Tasks; + #endif using Amazon.DynamoDBv2.DocumentModel; using Amazon.Runtime.Telemetry.Tracing; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -38,7 +41,7 @@ public partial interface ITransactWrite /// Represents a generic interface for writing/deleting/version-checking multiple items /// in a single DynamoDB table in a transaction. /// - public interface ITransactWrite : ITransactWrite + public interface ITransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : ITransactWrite { /// /// Creates a MultiTableTransactWrite object that is a combination @@ -175,10 +178,7 @@ public abstract partial class TransactWrite : ITransactWrite /// Represents a strongly-typed object for writing/deleting/version-checking multiple items /// in a single DynamoDB table in a transaction. /// -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif - public partial class TransactWrite : TransactWrite, ITransactWrite + public partial class TransactWrite<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : TransactWrite, ITransactWrite { private readonly DynamoDBContext _context; private readonly DynamoDBFlatConfig _config; diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWriteConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWriteConfig.cs index 7e7231d12ae0..24aa6f473388 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWriteConfig.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWriteConfig.cs @@ -18,10 +18,6 @@ namespace Amazon.DynamoDBv2.DataModel /// /// Input for the TransactWrite operation in the object-persistence programming model /// -#if NET8_0_OR_GREATER - // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] -#endif public class TransactWriteConfig : BaseOperationConfig { /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Utils.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Utils.cs index 699fcce63cfe..2e60b106e3ca 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Utils.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Utils.cs @@ -25,6 +25,7 @@ using System.Globalization; using System.Collections; using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -157,12 +158,8 @@ internal static void ValidateVersionType(Type memberType) throw new InvalidOperationException("Version property must be of primitive, numeric, integer, nullable type (e.g. int?, long?, byte?)"); } -#if NET8_0_OR_GREATER [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] internal static Type GetPrimitiveElementType(Type collectionType) -#else - internal static Type GetPrimitiveElementType(Type collectionType) -#endif { var elementType = Utils.GetElementType(collectionType); @@ -175,16 +172,12 @@ internal static Type GetPrimitiveElementType(Type collectionType) throw new InvalidOperationException("Unable to determine element type"); } -#if NET8_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2073", - Justification = "By the time the DynamoDB high level libraries got to this code path the collection type with the generic type would have already been found by the compiler preventing the element type from being trimmed.")] - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063", - Justification = "By the time the DynamoDB high level libraries got to this code path the collection type with the generic type would have already been found by the compiler preventing the element type from being trimmed.")] - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] - internal static Type GetElementType(Type collectionType) -#else + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2073", + Justification = "The user's type has been annotated with DynamicallyAccessedMemberTypes.All with the public API into the library. At this point the type will not be trimmed.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063", + Justification = "The user's type has been annotated with DynamicallyAccessedMemberTypes.All with the public API into the library. At this point the type will not be trimmed.")] + [return: DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] internal static Type GetElementType(Type collectionType) -#endif { var elementType = collectionType.GetElementType(); @@ -199,22 +192,14 @@ internal static Type GetElementType(Type collectionType) return elementType; } -#if NET8_0_OR_GREATER internal static bool ItemsToCollection([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, IEnumerable items, out object result) -#else - internal static bool ItemsToCollection(Type targetType, IEnumerable items, out object result) -#endif { return targetType.IsArray ? ItemsToArray(targetType, items, out result): //targetType is Array ItemsToIList(targetType, items, out result); //targetType is IList or has Add method. } -#if NET8_0_OR_GREATER private static bool ItemsToIList([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, IEnumerable items, out object result) -#else - private static bool ItemsToIList(Type targetType, IEnumerable items, out object result) -#endif { result = Utils.Instantiate(targetType); @@ -238,11 +223,7 @@ private static bool ItemsToIList(Type targetType, IEnumerable items, out return false; } -#if NET8_0_OR_GREATER private static bool ItemsToArray([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType, IEnumerable items, out object result) -#else - private static bool ItemsToArray(Type targetType, IEnumerable items, out object result) -#endif { var itemlist = items.ToList(); var array = (Array)InstantiateArray(targetType, itemlist.Count); @@ -339,38 +320,22 @@ internal static string ToLowerCamelCase(string value) new Type[] { typeof(DynamoDBContext) } }; -#if NET8_0_OR_GREATER internal static object InstantiateConverter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, IDynamoDBContext context) -#else - internal static object InstantiateConverter(Type objectType, IDynamoDBContext context) -#endif { return InstantiateHelper(objectType, validConverterConstructorInputs, new object[] { context }); } -#if NET8_0_OR_GREATER internal static object InstantiateArray([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, int length) -#else - internal static object InstantiateArray(Type objectType,int length) -#endif { return InstantiateHelper(objectType, validArrayConstructorInputs, new object[] { length }); } -#if NET8_0_OR_GREATER internal static object Instantiate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType) -#else - internal static object Instantiate(Type objectType) -#endif { return InstantiateHelper(objectType, validConstructorInputs, null); } -#if NET8_0_OR_GREATER private static object InstantiateHelper([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, Type[][] validConstructorInputs, object[] optionalInput = null) -#else - private static object InstantiateHelper(Type objectType, Type[][] validConstructorInputs, object[] optionalInput = null) -#endif { if (objectType == null) throw new ArgumentNullException("objectType"); @@ -394,11 +359,7 @@ private static object InstantiateHelper(Type objectType, Type[][] validConstruct throw new InvalidOperationException("Unable to find valid constructor for type " + objectType.FullName); } -#if NET8_0_OR_GREATER private static IEnumerable GetConstructors([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type typeInfo, Type[][] validConstructorInputs) -#else - private static IEnumerable GetConstructors(Type typeInfo, Type[][] validConstructorInputs) -#endif { foreach (var inputTypes in validConstructorInputs) { @@ -408,38 +369,22 @@ private static IEnumerable GetConstructors(Type typeInfo, Type[ } } -#if NET8_0_OR_GREATER public static bool CanInstantiate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType) -#else - public static bool CanInstantiate(Type objectType) -#endif { return CanInstantiateHelper(objectType, validConstructorInputs); } -#if NET8_0_OR_GREATER public static bool CanInstantiateArray([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType) -#else - public static bool CanInstantiateArray(Type objectType) -#endif { return objectType.IsArray && CanInstantiateHelper(objectType, validArrayConstructorInputs); } -#if NET8_0_OR_GREATER public static bool CanInstantiateConverter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType) -#else - public static bool CanInstantiateConverter(Type objectType) -#endif { return CanInstantiateHelper(objectType, validConverterConstructorInputs); } -#if NET8_0_OR_GREATER private static bool CanInstantiateHelper([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, Type[][] validConstructorInputs) -#else - private static bool CanInstantiateHelper(Type objectType, Type[][] validConstructorInputs) -#endif { var objectTypeWrapper = objectType; @@ -461,6 +406,7 @@ private static bool CanInstantiateHelper(Type objectType, Type[][] validConstruc return true; } + internal static Type GetType(MemberInfo member) { var pi = member as PropertyInfo; @@ -470,6 +416,7 @@ internal static Type GetType(MemberInfo member) return (pi != null ? pi.PropertyType : fi.FieldType); } + internal static bool IsReadWrite(MemberInfo member) { PropertyInfo property = member as PropertyInfo; @@ -489,11 +436,7 @@ internal static bool IsReadWrite(MemberInfo member) } } -#if NET8_0_OR_GREATER internal static bool ImplementsInterface([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type targetType, Type interfaceType) -#else - internal static bool ImplementsInterface(Type targetType, Type interfaceType) -#endif { if (!interfaceType.IsInterface) throw new ArgumentOutOfRangeException("interfaceType", "Type is not an interface"); @@ -538,11 +481,7 @@ private static bool IsValidMemberInfo(MemberInfo member) /// members from the derived types will be used while ignoring same-name members /// in base types to avoid returning duplicate members. /// -#if NET8_0_OR_GREATER - internal static List GetMembersFromType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) -#else - internal static List GetMembersFromType(Type type) -#endif + internal static List GetMembersFromType([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type type) { Dictionary members = new Dictionary(); diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs index d15b938aeb36..efa866ec7306 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs @@ -15,13 +15,15 @@ using Amazon.Runtime.Telemetry.Tracing; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { - public partial interface IAsyncSearch + public partial interface IAsyncSearch<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> { /// /// Initiates the asynchronous execution to get the next set of results from DynamoDB. @@ -48,7 +50,8 @@ public partial interface IAsyncSearch Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken)); } - public partial class AsyncSearch : IAsyncSearch + public partial class AsyncSearch<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T> : IAsyncSearch + { /// public virtual async Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken)) diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs index bea5ad0782bf..20e834aa2097 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs @@ -16,6 +16,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; using System.Threading; using System.Threading.Tasks; using Amazon.DynamoDBv2.DocumentModel; @@ -31,7 +33,7 @@ public partial class DynamoDBContext : IDynamoDBContext #region Save async /// - public async Task SaveAsync(T value, CancellationToken cancellationToken = default) + public async Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -41,7 +43,7 @@ public async Task SaveAsync(T value, CancellationToken cancellationToken = de /// [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - public async Task SaveAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -50,7 +52,7 @@ public async Task SaveAsync(T value, DynamoDBOperationConfig operationConfig, } /// - public async Task SaveAsync(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -59,7 +61,7 @@ public async Task SaveAsync(T value, SaveConfig saveConfig, CancellationToken } /// - public async Task SaveAsync(Type valueType, object value, CancellationToken cancellationToken = default) + public async Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -69,7 +71,7 @@ public async Task SaveAsync(Type valueType, object value, CancellationToken canc /// [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - public async Task SaveAsync(Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -78,7 +80,7 @@ public async Task SaveAsync(Type valueType, object value, DynamoDBOperationConfi } /// - public async Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) { @@ -91,7 +93,7 @@ public async Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, #region Load async /// - public async Task LoadAsync(object hashKey, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -101,7 +103,7 @@ public async Task LoadAsync(object hashKey, CancellationToken cancellation /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public async Task LoadAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -110,7 +112,7 @@ public async Task LoadAsync(object hashKey, DynamoDBOperationConfig operat } /// - public async Task LoadAsync(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -119,7 +121,7 @@ public async Task LoadAsync(object hashKey, LoadConfig loadConfig, Cancell } /// - public async Task LoadAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -129,7 +131,7 @@ public async Task LoadAsync(object hashKey, object rangeKey, CancellationT /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public async Task LoadAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -138,7 +140,7 @@ public async Task LoadAsync(object hashKey, object rangeKey, DynamoDBOpera } /// - public async Task LoadAsync(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -147,7 +149,7 @@ public async Task LoadAsync(object hashKey, object rangeKey, LoadConfig lo } /// - public async Task LoadAsync(T keyObject, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -157,7 +159,7 @@ public async Task LoadAsync(T keyObject, CancellationToken cancellationTok /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public async Task LoadAsync(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -166,7 +168,7 @@ public async Task LoadAsync(T keyObject, DynamoDBOperationConfig operation } /// - public async Task LoadAsync(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) { @@ -179,7 +181,7 @@ public async Task LoadAsync(T keyObject, LoadConfig loadConfig, Cancellati #region Delete async /// - public async Task DeleteAsync(T value, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -189,7 +191,7 @@ public async Task DeleteAsync(T value, CancellationToken cancellationToken = /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public async Task DeleteAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -198,7 +200,7 @@ public async Task DeleteAsync(T value, DynamoDBOperationConfig operationConfi } /// - public async Task DeleteAsync(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -207,7 +209,7 @@ public async Task DeleteAsync(T value, DeleteConfig deleteConfig, Cancellatio } /// - public async Task DeleteAsync(object hashKey, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -217,7 +219,7 @@ public async Task DeleteAsync(object hashKey, CancellationToken cancellationT /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public async Task DeleteAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -226,7 +228,7 @@ public async Task DeleteAsync(object hashKey, DynamoDBOperationConfig operati } /// - public async Task DeleteAsync(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -235,7 +237,7 @@ public async Task DeleteAsync(object hashKey, DeleteConfig deleteConfig, Canc } /// - public async Task DeleteAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -245,7 +247,7 @@ public async Task DeleteAsync(object hashKey, object rangeKey, CancellationTo /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public async Task DeleteAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -254,7 +256,7 @@ public async Task DeleteAsync(object hashKey, object rangeKey, DynamoDBOperat } /// - public async Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) { @@ -332,7 +334,7 @@ public async Task ExecuteBatchGetAsync(params IBatchGet[] batches) #region Scan async /// - public IAsyncSearch ScanAsync(IEnumerable conditions) + public IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions) { using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) { @@ -343,7 +345,7 @@ public IAsyncSearch ScanAsync(IEnumerable conditions) /// [Obsolete("Use the ScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ScanAsync.")] - public IAsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null) + public IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null) { using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) { @@ -353,7 +355,7 @@ public IAsyncSearch ScanAsync(IEnumerable conditions, Dynam } /// - public IAsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig) + public IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions, ScanConfig scanConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) { @@ -363,7 +365,7 @@ public IAsyncSearch ScanAsync(IEnumerable conditions, ScanC } /// - public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig) + public IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) { @@ -376,7 +378,7 @@ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig) /// [Obsolete("Use the FromScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromScanAsync.")] - public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null) + public IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) { @@ -388,7 +390,7 @@ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDB } /// - public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig) + public IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) { @@ -404,7 +406,7 @@ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScan #region Query async /// - public IAsyncSearch QueryAsync(object hashKeyValue) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -415,7 +417,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue) /// [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] - public IAsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfig operationConfig = null) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, DynamoDBOperationConfig operationConfig = null) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -425,7 +427,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfi } /// - public IAsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfig) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryConfig queryConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -435,7 +437,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfi } /// - public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -449,7 +451,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnu /// [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] - public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -462,7 +464,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnu } /// - public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig) + public IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) { @@ -475,7 +477,7 @@ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnu } /// - public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig) + public IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) { @@ -488,7 +490,7 @@ public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig) /// [Obsolete("Use the FromQueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromQueryAsync.")] - public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null) + public IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) { @@ -500,7 +502,7 @@ public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, Dynam } /// - public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig) + public IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig) { using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) { diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs index 98a1bee4674d..700500f99e07 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs @@ -16,9 +16,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -40,7 +42,7 @@ partial interface IDynamoDBContext /// Object to save. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task SaveAsync(T value, CancellationToken cancellationToken = default); + Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, CancellationToken cancellationToken = default); /// /// Saves an object to DynamoDB. @@ -54,7 +56,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - Task SaveAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Saves an object to DynamoDB. @@ -67,7 +69,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task SaveAsync(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default); + Task SaveAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default); /// /// Saves an object to DynamoDB. @@ -79,7 +81,7 @@ partial interface IDynamoDBContext /// Object to save. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task SaveAsync(Type valueType, object value, CancellationToken cancellationToken = default); + Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, CancellationToken cancellationToken = default); /// /// Saves an object to DynamoDB. @@ -93,7 +95,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - Task SaveAsync(Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Saves an object to DynamoDB. @@ -106,7 +108,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default); + Task SaveAsync([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default); #endregion @@ -123,7 +125,7 @@ partial interface IDynamoDBContext /// Hash key element of the target item. /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. - Task LoadAsync(object hashKey, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given hash key. @@ -140,7 +142,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - Task LoadAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given hash key. @@ -154,7 +156,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task LoadAsync(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given hash-and-range primary key. @@ -167,7 +169,7 @@ partial interface IDynamoDBContext /// Range key element of the target item. /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. - Task LoadAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given hash-and-range primary key. @@ -186,7 +188,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - Task LoadAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given hash-and-range primary key. @@ -201,7 +203,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task LoadAsync(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given key. @@ -217,7 +219,7 @@ partial interface IDynamoDBContext /// Key of the target item. /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. - Task LoadAsync(T keyObject, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given key. @@ -243,7 +245,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// Object of type T, populated with the properties of the item loaded from DynamoDB. [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - Task LoadAsync(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Loads an object from DynamoDB for the given key. @@ -259,7 +261,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task LoadAsync(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default); + Task LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default); #endregion @@ -277,7 +279,7 @@ partial interface IDynamoDBContext /// Object to delete. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(T value, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to given object. @@ -293,7 +295,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - Task DeleteAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to given object. @@ -308,7 +310,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to given hash key. @@ -322,7 +324,7 @@ partial interface IDynamoDBContext /// Hash key element of the object to delete. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(object hashKey, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to given hash key. @@ -338,7 +340,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - Task DeleteAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to given hash key. @@ -353,7 +355,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to a given hash-and-range primary key. @@ -368,7 +370,7 @@ partial interface IDynamoDBContext /// Range key element of the object to delete. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to a given hash-and-range primary key. @@ -385,7 +387,7 @@ partial interface IDynamoDBContext /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - Task DeleteAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default); /// /// Deletes an item in DynamoDB corresponding to a given hash-and-range primary key. @@ -401,7 +403,7 @@ partial interface IDynamoDBContext /// Config object that can be used to override properties on the table's context for this request. /// Token which can be used to cancel the task. /// A Task that can be used to poll or wait for results, or both. - Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); + Task DeleteAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default); #endregion @@ -482,7 +484,7 @@ partial interface IDynamoDBContext /// Conditions that the results should meet. /// /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch ScanAsync(IEnumerable conditions); + IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions); /// /// Configures an async Scan operation against DynamoDB, finding items @@ -496,7 +498,7 @@ partial interface IDynamoDBContext /// AsyncSearch which can be used to retrieve DynamoDB data. [Obsolete("Use the ScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ScanAsync.")] - IAsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null); + IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null); /// /// Configures an async Scan operation against DynamoDB, finding items @@ -508,7 +510,7 @@ partial interface IDynamoDBContext /// /// Config object that can be used to override properties on the table's context for this request. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig); + IAsyncSearch ScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(IEnumerable conditions, ScanConfig scanConfig); /// /// Configures an async Scan operation against DynamoDB, finding items @@ -517,7 +519,7 @@ partial interface IDynamoDBContext /// Type of object. /// Scan request object. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig); + IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig); /// /// Configures an async Scan operation against DynamoDB, finding items @@ -528,7 +530,7 @@ partial interface IDynamoDBContext /// Config object which can be used to override the table used. /// AsyncSearch which can be used to retrieve DynamoDB data. [Obsolete("Use the FromScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromScanAsync.")] - IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null); + IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null); /// /// Configures an async Scan operation against DynamoDB, finding items @@ -538,7 +540,7 @@ partial interface IDynamoDBContext /// Scan request object. /// Config object that can be used to override properties on the table's context for this request. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig); + IAsyncSearch FromScanAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig); #endregion @@ -551,7 +553,7 @@ partial interface IDynamoDBContext /// Type of object. /// Hash key of the items to query. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch QueryAsync(object hashKeyValue); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue); /// /// Configures an async Query operation against DynamoDB, finding items @@ -562,7 +564,7 @@ partial interface IDynamoDBContext /// Config object which can be used to override the table used. /// AsyncSearch which can be used to retrieve DynamoDB data. [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] - IAsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfig operationConfig = null); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, DynamoDBOperationConfig operationConfig = null); /// /// Configures an async Query operation against DynamoDB, finding items @@ -572,7 +574,7 @@ partial interface IDynamoDBContext /// Hash key of the items to query. /// Config object that can be used to override properties on the table's context for this request. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfig); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryConfig queryConfig); /// /// Configures an async Query operation against DynamoDB, finding items @@ -587,7 +589,7 @@ partial interface IDynamoDBContext /// For QueryOperator.Betwee, values should be two values. /// /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values); /// /// Configures an async Query operation against DynamoDB, finding items @@ -604,7 +606,7 @@ partial interface IDynamoDBContext /// Config object which can be used to override the table used. /// AsyncSearch which can be used to retrieve DynamoDB data. [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] - IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null); /// /// Configures an async Query operation against DynamoDB, finding items @@ -620,7 +622,7 @@ partial interface IDynamoDBContext /// /// Config object that can be used to override properties on the table's context for this request. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig); + IAsyncSearch QueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig); /// /// Configures an async Query operation against DynamoDB using a mid-level document model @@ -629,7 +631,7 @@ partial interface IDynamoDBContext /// Type of object. /// Mid-level, document model query request object. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig); + IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig); /// /// Configures an async Query operation against DynamoDB, finding items @@ -640,7 +642,7 @@ partial interface IDynamoDBContext /// Config object which can be used to override the table used. /// AsyncSearch which can be used to retrieve DynamoDB data. [Obsolete("Use the FromQueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromQueryAsync.")] - IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null); + IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null); /// /// Configures an async Query operation against DynamoDB using a mid-level document model @@ -650,7 +652,7 @@ partial interface IDynamoDBContext /// Mid-level, document model query request object. /// Config object that can be used to override properties on the table's context for this request. /// AsyncSearch which can be used to retrieve DynamoDB data. - IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig); + IAsyncSearch FromQueryAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig); #endregion } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/Context.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/Context.Sync.cs index d268cea1fc2f..199d2ea4a882 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/Context.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/Context.Sync.cs @@ -14,8 +14,10 @@ */ using System; +using System.Diagnostics.CodeAnalysis; using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -24,20 +26,20 @@ public partial class DynamoDBContext : IDynamoDBContext #region Table methods /// - public ITable GetTargetTable() + public ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>() { return GetTargetTableInternal(new DynamoDBFlatConfig(null, Config)); } /// [Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")] - public ITable GetTargetTable(DynamoDBOperationConfig operationConfig = null) + public ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null) { return GetTargetTableInternal(new DynamoDBFlatConfig(operationConfig, Config)); } /// - public ITable GetTargetTable(GetTargetTableConfig getTargetTableConfig) + public ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(GetTargetTableConfig getTargetTableConfig) { return GetTargetTableInternal(new DynamoDBFlatConfig(getTargetTableConfig?.ToDynamoDBOperationConfig(), Config)); } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/IDynamoDBContext.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/IDynamoDBContext.Sync.cs index 61c921feafcf..c48b41f42afd 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/IDynamoDBContext.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_netstandard/IDynamoDBContext.Sync.cs @@ -14,8 +14,10 @@ */ using System; +using System.Diagnostics.CodeAnalysis; using Amazon.DynamoDBv2.DocumentModel; +using ThirdParty.RuntimeBackports; namespace Amazon.DynamoDBv2.DataModel { @@ -32,7 +34,7 @@ partial interface IDynamoDBContext /// /// Type to retrieve table for /// Table object - ITable GetTargetTable(); + ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(); /// /// Retrieves the target table for the specified type @@ -40,14 +42,14 @@ partial interface IDynamoDBContext /// Type to retrieve table for /// Table object [Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")] - ITable GetTargetTable(DynamoDBOperationConfig operationConfig = null); + ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(DynamoDBOperationConfig operationConfig = null); /// /// Retrieves the target table for the specified type /// /// Type to retrieve table for /// Table object - ITable GetTargetTable(GetTargetTableConfig getTargetTableConfig); + ITable GetTargetTable<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] T>(GetTargetTableConfig getTargetTableConfig); #endregion } diff --git a/sdk/src/Services/DynamoDBv2/Custom/Internal/InternalConstants.cs b/sdk/src/Services/DynamoDBv2/Custom/Internal/InternalConstants.cs index 039eb812502a..45bd84058aed 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/Internal/InternalConstants.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/Internal/InternalConstants.cs @@ -13,10 +13,17 @@ * permissions and limitations under the License. */ -namespace Amazon.DynamoDBv2.Custom.Internal +using System.Diagnostics.CodeAnalysis; +using ThirdParty.RuntimeBackports; + +namespace Amazon.DynamoDBv2 { internal static class InternalConstants { - internal const string RequiresUnreferencedCodeMessage = "The Amazon DynamoDB high level libraries in the DataModel namespace have not been updated to support Native AOT."; + /// + /// This is DynamicallyAccessedMemberTypes value that must be used whenever identifing the System.Type that users will + /// use to the DataModel library for loading and saving data. + /// + internal const DynamicallyAccessedMemberTypes DataModelModeledType = DynamicallyAccessedMemberTypes.All; } }