Skip to content

Commit

Permalink
Add convenience properties in DotNetRuntimeInfo for quick classificat…
Browse files Browse the repository at this point in the history
…ion of used runtime.
  • Loading branch information
Washi1337 committed Aug 19, 2022
1 parent 90d2ba0 commit 505da7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/AsmResolver.DotNet/DotNetRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ public Version Version
get;
}

/// <summary>
/// Gets a value indicating whether the application targets the .NET or .NET Core runtime or not.
/// </summary>
public bool IsNetCoreApp => Name == NetCoreApp;

/// <summary>
/// Gets a value indicating whether the application targets the .NET Framework runtime or not.
/// </summary>
public bool IsNetFramework => Name == NetFramework;

/// <summary>
/// Gets a value indicating whether the application targets the .NET standard specification or not.
/// </summary>
public bool IsNetStandard => Name == NetStandard;

/// <summary>
/// Attempts to parse the framework name as provided in <see cref="TargetFrameworkAttribute"/>.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions test/AsmResolver.DotNet.Tests/ModuleDefinitionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public void PersistentFileReferences()
public void DetectTargetNetFramework40()
{
var module = ModuleDefinition.FromBytes(Properties.Resources.HelloWorld);
Assert.True(module.OriginalTargetRuntime.IsNetFramework);
Assert.Contains(DotNetRuntimeInfo.NetFramework, module.OriginalTargetRuntime.Name);
Assert.Equal(4, module.OriginalTargetRuntime.Version.Major);
Assert.Equal(0, module.OriginalTargetRuntime.Version.Minor);
Expand All @@ -336,6 +337,7 @@ public void DetectTargetNetFramework40()
public void DetectTargetNetCore()
{
var module = ModuleDefinition.FromBytes(Properties.Resources.HelloWorld_NetCore);
Assert.True(module.OriginalTargetRuntime.IsNetCoreApp);
Assert.Contains(DotNetRuntimeInfo.NetCoreApp, module.OriginalTargetRuntime.Name);
Assert.Equal(2, module.OriginalTargetRuntime.Version.Major);
Assert.Equal(2, module.OriginalTargetRuntime.Version.Minor);
Expand All @@ -345,6 +347,7 @@ public void DetectTargetNetCore()
public void DetectTargetStandard()
{
var module = ModuleDefinition.FromFile(typeof(TestCases.Types.Class).Assembly.Location);
Assert.True(module.OriginalTargetRuntime.IsNetStandard);
Assert.Contains(DotNetRuntimeInfo.NetStandard, module.OriginalTargetRuntime.Name);
Assert.Equal(2, module.OriginalTargetRuntime.Version.Major);
}
Expand Down

0 comments on commit 505da7a

Please sign in to comment.