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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>5.0</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(StrongName)'=='True'">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)build/MathNet.Numerics.snk</AssemblyOriginatorKeyFile>
Expand Down
4 changes: 4 additions & 0 deletions src/Numerics/LinearAlgebra/Solvers/SolverSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

namespace MathNet.Numerics.LinearAlgebra.Solvers
{
#if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Uses Activator.CreateInstance which might require members that are not statically referenced")]
#endif
public static class SolverSetup<T> where T : struct, IEquatable<T>, IFormattable
{
/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion src/Numerics/Providers/ProviderProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// </copyright>

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace MathNet.Numerics.Providers
Expand All @@ -43,10 +44,19 @@ public ProviderProbe(string typeName, bool disabled = false)
_creator = new Lazy<IProviderCreator<T>>(() =>
{
var type = Type.GetType(typeName);
return type is null ? null : Activator.CreateInstance(type) as IProviderCreator<T>;
return CreateProvider(type);
}, LazyThreadSafetyMode.ExecutionAndPublication);
}

private static IProviderCreator<T> CreateProvider(
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
Type type)
{
return type == null ? null : Activator.CreateInstance(type) as IProviderCreator<T>;
}

public T Create()
{
if (_disabled)
Expand Down