From 9a4492924c3e08521899bb8636a5f052c840cb01 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sun, 21 Jan 2024 17:27:08 -0800 Subject: [PATCH] Add support for AOT compilation --- src/Prometheus.SystemMetrics/Native/WindowsNative.cs | 2 +- .../Prometheus.SystemMetrics.csproj | 5 +++-- .../ServiceCollectionExtensions.cs | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Prometheus.SystemMetrics/Native/WindowsNative.cs b/src/Prometheus.SystemMetrics/Native/WindowsNative.cs index b050b12..9b2a920 100644 --- a/src/Prometheus.SystemMetrics/Native/WindowsNative.cs +++ b/src/Prometheus.SystemMetrics/Native/WindowsNative.cs @@ -87,7 +87,7 @@ public class MEMORYSTATUSEX /// public MEMORYSTATUSEX() { - dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX)); + dwLength = (uint)Marshal.SizeOf(); } } } diff --git a/src/Prometheus.SystemMetrics/Prometheus.SystemMetrics.csproj b/src/Prometheus.SystemMetrics/Prometheus.SystemMetrics.csproj index f72a2cb..045deed 100644 --- a/src/Prometheus.SystemMetrics/Prometheus.SystemMetrics.csproj +++ b/src/Prometheus.SystemMetrics/Prometheus.SystemMetrics.csproj @@ -1,9 +1,10 @@  - netstandard2.0;net462 + netstandard2.0;net462;net80 enable latestMajor + true prometheus-net.SystemMetrics prometheus-net.SystemMetrics Daniel Lo Nigro @@ -30,7 +31,7 @@ - + diff --git a/src/Prometheus.SystemMetrics/ServiceCollectionExtensions.cs b/src/Prometheus.SystemMetrics/ServiceCollectionExtensions.cs index fcf3c4d..e25afa5 100644 --- a/src/Prometheus.SystemMetrics/ServiceCollectionExtensions.cs +++ b/src/Prometheus.SystemMetrics/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Extensions.DependencyInjection; using Prometheus.SystemMetrics.Collectors; namespace Prometheus.SystemMetrics @@ -38,7 +39,11 @@ public static IServiceCollection AddSystemMetrics(this IServiceCollection servic /// Adds a system metric collector to the /// /// Metric to add +#if NET7_0_OR_GREATER + public static IServiceCollection AddSystemMetricCollector<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IServiceCollection services) +#else public static IServiceCollection AddSystemMetricCollector(this IServiceCollection services) +#endif where T : class, ISystemMetricCollector { services.AddSingleton();