Skip to content

Commit d10cc8a

Browse files
committed
examples
1 parent fb7e77f commit d10cc8a

6 files changed

Lines changed: 103 additions & 2 deletions

File tree

v2/RSCGExamplesData/GeneratorDataRec.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
},
524524
{
525525
"ID": "COM",
526-
"Category": 1,
526+
"Category": 28,
527527
"dtStart": "2023-11-20T00:00:00",
528528
"show": true
529529
},
@@ -1157,7 +1157,13 @@
11571157
{
11581158
"ID":"Immediate.APIs",
11591159
"Category": 15,
1160-
"dtStart": "2024-09-20T00:00:00",
1160+
"dtStart": "2024-09-27T00:00:00",
1161+
"show": true
1162+
},
1163+
{
1164+
"ID":"NativeObjects",
1165+
"Category": 28,
1166+
"dtStart": "2025-03-28T00:00:00",
11611167
"show": true
11621168
}
11631169
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"generator":{
3+
"name":"NativeObjects",
4+
"nuget":[
5+
"https://www.nuget.org/packages/NativeObjects/"
6+
],
7+
"link":"https://github.com/kevingosse/NativeObjects",
8+
"author":"Kevin Gosse",
9+
"source":"https://github.com/kevingosse/NativeObjects"
10+
},
11+
"data":{
12+
"goodFor":["Object to IntPtr and back"],
13+
"csprojDemo":"NativeObjectsDemo.csproj",
14+
"csFiles":["Program.cs"],
15+
"excludeDirectoryGenerated":[""],
16+
"includeAdditionalFiles":[""]
17+
},
18+
"links":{
19+
"blog":"",
20+
"video":""
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35913.81 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeObjectsDemo", "NativeObjectsDemo\NativeObjectsDemo.csproj", "{3D03ACB6-DBA2-45C3-B0FD-04CADB235D72}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3D03ACB6-DBA2-45C3-B0FD-04CADB235D72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3D03ACB6-DBA2-45C3-B0FD-04CADB235D72}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3D03ACB6-DBA2-45C3-B0FD-04CADB235D72}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3D03ACB6-DBA2-45C3-B0FD-04CADB235D72}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3640907E-3682-4E8C-9ED2-1E663627F74F}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="NativeObjects" Version="1.3.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
12+
</ItemGroup>
13+
<PropertyGroup>
14+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
15+
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
16+
</PropertyGroup>
17+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NativeObjectsDemo;
2+
[NativeObject]
3+
public interface IPerson
4+
{
5+
public int CalculateAge();
6+
}
7+
class Person : IPerson
8+
{
9+
public DateTime DateOfBirth { get; set; }
10+
11+
public int CalculateAge()
12+
{
13+
14+
return (int)DateTime.Now.Subtract(DateOfBirth).TotalDays / 365;
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using NativeObjectsDemo;
2+
Person p = new Person();
3+
4+
p.DateOfBirth= new DateTime(1970,4,16);
5+
using (var nativ = NativeObjects.IPerson.Wrap(p))
6+
{
7+
SomeNativeCode((IntPtr)nativ.Object);
8+
}
9+
10+
static void SomeNativeCode(IntPtr nativePerson)
11+
{
12+
var p = NativeObjects.IPerson.Wrap(nativePerson);
13+
Console.WriteLine($"Age: {p.CalculateAge()}");
14+
15+
}

0 commit comments

Comments
 (0)