This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup initial C# CoreWrapper class and utilize it in sample cli app
- Loading branch information
1 parent
2fe1d80
commit beb2e8f
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mgtt.CoreWrapper | ||
{ | ||
public class CoreWrapper | ||
{ | ||
public static string _libraryPath {get; set;} | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "add")] | ||
public static extern int Add(int a, int b); | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "subtract")] | ||
public static extern int Subtract(int a, int b); | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "multiply")] | ||
public static extern int Multiply(int a, int b); | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "divide")] | ||
public static extern float Divide(float a, float b); | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "getCircleArea")] | ||
public static extern float GetCircleArea(float radius); | ||
|
||
[DllImport("{LibraryPath}", EntryPoint = "getCircleCircumference")] | ||
public static extern float GetCircleCircumference(float radius); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.9.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using CommandLine; | ||
|
||
namespace Mgtt.CoreWrapper; | ||
class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
Options options = null; | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(o => options = o); | ||
|
||
if (options == null) | ||
{ | ||
Console.WriteLine("Usage: dotnet run --coreLibraryPath <coreLibraryPath>"); | ||
return 1; | ||
} | ||
|
||
CoreWrapper._libraryPath = options.CoreLibraryPath; | ||
|
||
int resultAdd = CoreWrapper.Add(10, 5); | ||
Console.WriteLine("Addition result: " + resultAdd); | ||
|
||
int resultSubtract = CoreWrapper.Subtract(10, 5); | ||
Console.WriteLine("Subtraction result: " + resultSubtract); | ||
|
||
int resultMultiply = CoreWrapper.Multiply(10, 5); | ||
Console.WriteLine("Multiplication result: " + resultMultiply); | ||
|
||
float resultDivide = CoreWrapper.Divide(10.0f, 2.0f); | ||
Console.WriteLine("Division result: " + resultDivide); | ||
|
||
float radius = 5.0f; | ||
|
||
float area = CoreWrapper.GetCircleArea(radius); | ||
Console.WriteLine("Circle area: " + area); | ||
|
||
float circumference = CoreWrapper.GetCircleCircumference(radius); | ||
Console.WriteLine("Circle circumference: " + circumference); | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
public class Options | ||
{ | ||
[Option("coreLibraryPath", Required = true, HelpText = "Path to the core library.")] | ||
public string CoreLibraryPath { get; set; } | ||
} |