diff --git a/.buildkite/DockerFile b/.buildkite/DockerFile index 9ccd51b4944..e8e0211202b 100644 --- a/.buildkite/DockerFile +++ b/.buildkite/DockerFile @@ -24,6 +24,7 @@ COPY ./tests/*.Build.props ./tests/ COPY src/*/*.?sproj ./src/ COPY tests/*/*.?sproj ./tests/ COPY benchmarks/*/*.?sproj ./benchmarks/ +COPY examples/*/*.?sproj ./examples/ # this puts the project files back into original location since COPY flattens RUN for file in $(find . -name "*.?sproj"); do echo mkdir -p $(dirname $file)/$(basename ${file%.*})/ && echo mv $file $(dirname $file)/$(basename ${file%.*})/; done diff --git a/.ci/DockerFile b/.ci/DockerFile index 5ba098c2552..1deaccd4986 100644 --- a/.ci/DockerFile +++ b/.ci/DockerFile @@ -24,6 +24,7 @@ COPY ./tests/*.Build.props ./tests/ COPY src/*/*.?sproj ./src/ COPY tests/*/*.?sproj ./tests/ COPY benchmarks/*/*.?sproj ./benchmarks/ +COPY examples/*/*.?sproj ./examples/ # this puts the project files back into original location since COPY flattens RUN for file in $(find . -name "*.?sproj"); do echo mkdir -p $(dirname $file)/$(basename ${file%.*})/ && echo mv $file $(dirname $file)/$(basename ${file%.*})/; done diff --git a/Elasticsearch.sln b/Elasticsearch.sln index 242fd14cf6b..cecd196bedb 100644 --- a/Elasticsearch.sln +++ b/Elasticsearch.sln @@ -57,6 +57,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.ClusterLauncher", "te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests\Tests.csproj", "{6FD804B2-CE80-41CB-A411-2023F34C18FE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aot", "examples\aot\aot.csproj", "{3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -103,6 +107,10 @@ Global {6FD804B2-CE80-41CB-A411-2023F34C18FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FD804B2-CE80-41CB-A411-2023F34C18FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FD804B2-CE80-41CB-A411-2023F34C18FE}.Release|Any CPU.Build.0 = Release|Any CPU + {3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -118,6 +126,7 @@ Global {68D1BFDC-F447-4D2C-AF81-537807636610} = {1FE49D14-216A-41EE-A177-E42BFF53E0DC} {F6162603-D134-4121-8106-2BA4DAD7350B} = {362B2776-4B29-46AB-B237-56776B5372B6} {6FD804B2-CE80-41CB-A411-2023F34C18FE} = {362B2776-4B29-46AB-B237-56776B5372B6} + {3FA9C99A-7DA0-4DF2-89C0-BDDFC97E2CB7} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CE74F821-B001-4C69-A58D-CF81F8B0B632} diff --git a/examples/aot/Program.cs b/examples/aot/Program.cs new file mode 100644 index 00000000000..07c1f20b26b --- /dev/null +++ b/examples/aot/Program.cs @@ -0,0 +1,59 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; +using System.Text.Json.Serialization; + +using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Serialization; +using Elastic.Transport; +using Elastic.Transport.Extensions; + +namespace AOT; + +public static class Program +{ + public static void Main(string[] args) + { + var nodePool = new SingleNodePool(new Uri("http://localhost:9200")); + var settings = new ElasticsearchClientSettings( + nodePool, + sourceSerializer: (_, settings) => + new DefaultSourceSerializer(settings, UserTypeSerializerContext.Default) + ) + .DefaultMappingFor(x => x.IndexName("index")); + + var client = new ElasticsearchClient(settings); + + var person = new Person + { + Id = 1234, + FirstName = "Florian", + LastName = "Bernd" + }; + + Trace.Assert(client.Infer.Id(person) == "1234"); + + var indexRequest = new IndexRequest(person); + var indexRequestBody = client.ElasticsearchClientSettings.RequestResponseSerializer.SerializeToString(indexRequest); + var indexRequest2 = client.ElasticsearchClientSettings.RequestResponseSerializer.Deserialize>(indexRequestBody)!; + + Trace.Assert(indexRequest.Document == indexRequest2.Document); + } +} + +internal sealed record Person +{ + public long? Id { get; init; } + public required string FirstName { get; init; } + public required string LastName { get; init; } + public DateTimeOffset? BirthDate { get; init; } +} + +[JsonSerializable(typeof(Person), GenerationMode = JsonSourceGenerationMode.Default)] +internal sealed partial class UserTypeSerializerContext : + JsonSerializerContext +{ +} diff --git a/examples/aot/aot.csproj b/examples/aot/aot.csproj new file mode 100644 index 00000000000..cec1671aa11 --- /dev/null +++ b/examples/aot/aot.csproj @@ -0,0 +1,17 @@ + + + + Exe + net9.0 + + enable + true + true + false + + + + + + + diff --git a/src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj b/src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj index 13992fe296f..ef506742514 100644 --- a/src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj +++ b/src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj @@ -31,7 +31,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Elastic.Clients.Elasticsearch/_Shared/Core/Infer/DynamicPropertyAccessor.cs b/src/Elastic.Clients.Elasticsearch/_Shared/Core/Infer/DynamicPropertyAccessor.cs index 02aeeb6e846..deb5e175874 100644 --- a/src/Elastic.Clients.Elasticsearch/_Shared/Core/Infer/DynamicPropertyAccessor.cs +++ b/src/Elastic.Clients.Elasticsearch/_Shared/Core/Infer/DynamicPropertyAccessor.cs @@ -50,11 +50,9 @@ internal static class DynamicPropertyAccessor // Build compiled getter delegate. -#pragma warning disable IL3050 -#pragma warning disable IL2060 +#pragma warning disable IL3050, IL2060 var getterDelegateFactory = MakeDelegateMethodInfo.MakeGenericMethod(type, getterMethod.ReturnType); -#pragma warning restore IL3050 -#pragma warning restore IL2060 +#pragma warning restore IL3050, IL2060 var genericGetterDelegate = (Func)getterDelegateFactory.Invoke(null, [getterMethod])!; return instance => retrieverFunc(genericGetterDelegate, instance); diff --git a/src/Playground/Person.cs b/src/Playground/Person.cs index c1107bcfba3..62f758eab7d 100644 --- a/src/Playground/Person.cs +++ b/src/Playground/Person.cs @@ -4,6 +4,7 @@ using System.Runtime.Serialization; using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.QueryDsl; namespace Playground { @@ -30,6 +31,8 @@ public class Person public string Data { get; init; } = "NOTHING"; public DateTimeKind Enum { get; init; } + + public Query? Q { get; init; } } public class PersonV3 diff --git a/src/Playground/Playground.csproj b/src/Playground/Playground.csproj index 1d27a40460d..06e0eb5b9c0 100644 --- a/src/Playground/Playground.csproj +++ b/src/Playground/Playground.csproj @@ -13,8 +13,8 @@ - - + +