Skip to content

Commit 7088585

Browse files
committed
md files
1 parent d10cc8a commit 7088585

38 files changed

Lines changed: 802 additions & 232 deletions

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# RSCG - 192 Examples of Roslyn Source Code Generators / 14 created by Microsoft /
1+
# RSCG - 193 Examples of Roslyn Source Code Generators / 14 created by Microsoft /
22

3-
## Latest Update : 2025-03-26 => 26 March 2025
3+
## Latest Update : 2025-03-28 => 28 March 2025
44

55
If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)***
66

@@ -20,11 +20,34 @@ If you want to be notified each time I add a new RSCG example , please click htt
2020

2121
## Content
2222

23-
Those are the 192 Roslyn Source Code Generators that I have tested you can see and download source code example.
23+
Those are the 193 Roslyn Source Code Generators that I have tested you can see and download source code example.
2424
( including 14 from Microsoft )
25+
### 193. [NativeObjects](https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects) , in the [WinAPI](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#winapi) category
26+
27+
Generated on : 2025-03-28 => 28 March 2025
28+
29+
<details>
30+
<summary>Expand</summary>
31+
32+
33+
34+
Author: Kevin Gosse
35+
36+
Source generator for native interop.
37+
Generates implementation for interfaces to expose managed objects as COM-like, or call methods on COM-like native objects.
38+
39+
Nuget: [https://www.nuget.org/packages/NativeObjects/](https://www.nuget.org/packages/NativeObjects/)
40+
41+
42+
Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects](https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects)
43+
44+
Source: [https://github.com/kevingosse/NativeObjects](https://github.com/kevingosse/NativeObjects)
45+
46+
</details>
47+
2548
### 192. [immediate.apis](https://ignatandrei.github.io/RSCG_Examples/v2/docs/immediate.apis) , in the [API](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#api) category
2649

27-
Generated on : 2024-09-20 => 20 September 2024
50+
Generated on : 2024-09-27 => 27 September 2024
2851

2952
<details>
3053
<summary>Expand</summary>
@@ -2388,7 +2411,7 @@ Source: [https://github.com/ignatandrei/RSCG_InterceptorTemplate](https://github
23882411

23892412
</details>
23902413

2391-
### 88. [Com](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Com) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category
2414+
### 88. [Com](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Com) , in the [WinAPI](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#winapi) category
23922415

23932416
Generated on : 2023-11-20 => 20 November 2023
23942417

later.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Just later
22

3-
## Latest Update : 2025-03-26 => 26 March 2025
3+
## Latest Update : 2025-03-28 => 28 March 2025
44

55

66

v2/Generator/all.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Nr,Key,Source,Category
8686
85,OptValidator, https://github.com/dotnet/runtime,EnhancementClass
8787
86,ConfigBinder, https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#configuration-binding-source-generator,API
8888
87,RDG, https://github.com/dotnet/aspnetcore,API
89-
88,COM, https://github.com/dotnet/runtime,EnhancementProject
89+
88,COM, https://github.com/dotnet/runtime,WinAPI
9090
89,InterceptorTemplate, https://github.com/ignatandrei/RSCG_InterceptorTemplate,Templating
9191
90,TelemetryLogging, https://github.com/dotnet/extensions,EnhancementClass
9292
91,Ling.Audit, https://github.com/ling921/dotnet-lib/,EnhancementClass
@@ -191,3 +191,4 @@ Nr,Key,Source,Category
191191
190,PMart.Enumeration, https://github.com/p-martinho/Enumeration,Enum
192192
191,rscg_demeter, https://github.com/ignatandrei/rscg_demeter/,FunctionalProgramming
193193
192,Immediate.APIs, https://github.com/immediateplatform/immediate.apis,API
194+
193,NativeObjects, https://github.com/kevingosse/NativeObjects,WinAPI

v2/rscg_examples/InterceptorTemplate/src/.tours/InterceptorTemplate.tour

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -41,66 +41,6 @@
4141
}
4242

4343

44-
,{
45-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_Test_2.cs",
46-
"description": "Generated File 10 from 10 : RSCG_DemoObjects.Person_Test_2.cs ",
47-
"line": 1
48-
}
49-
50-
,{
51-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_TestFullNameWithArguments_6.cs",
52-
"description": "Generated File 9 from 10 : RSCG_DemoObjects.Person_TestFullNameWithArguments_6.cs ",
53-
"line": 1
54-
}
55-
56-
,{
57-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_ShowRandomPersonNumber_7.cs",
58-
"description": "Generated File 8 from 10 : RSCG_DemoObjects.Person_ShowRandomPersonNumber_7.cs ",
59-
"line": 1
60-
}
61-
62-
,{
63-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_PersonsLoaded_5.cs",
64-
"description": "Generated File 7 from 10 : RSCG_DemoObjects.Person_PersonsLoaded_5.cs ",
65-
"line": 1
66-
}
67-
68-
,{
69-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_PersonsLoaded_4.cs",
70-
"description": "Generated File 6 from 10 : RSCG_DemoObjects.Person_PersonsLoaded_4.cs ",
71-
"line": 1
72-
}
73-
74-
,{
75-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_FullName_3.cs",
76-
"description": "Generated File 5 from 10 : RSCG_DemoObjects.Person_FullName_3.cs ",
77-
"line": 1
78-
}
79-
80-
,{
81-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.Person_FullName_1.cs",
82-
"description": "Generated File 4 from 10 : RSCG_DemoObjects.Person_FullName_1.cs ",
83-
"line": 1
84-
}
85-
86-
,{
87-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.PersonLoader_SavePerson_8.cs",
88-
"description": "Generated File 3 from 10 : RSCG_DemoObjects.PersonLoader_SavePerson_8.cs ",
89-
"line": 1
90-
}
91-
92-
,{
93-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.PersonLoader_Connect_9.cs",
94-
"description": "Generated File 2 from 10 : RSCG_DemoObjects.PersonLoader_Connect_9.cs ",
95-
"line": 1
96-
}
97-
98-
,{
99-
"file": "RSCG_InterceptorTemplateConsole/obj/GX/RSCG_InterceptorTemplate/RSCG_InterceptorTemplate.MethodIntercept/RSCG_DemoObjects.IPersonLoader_InsertPerson_10.cs",
100-
"description": "Generated File 1 from 10 : RSCG_DemoObjects.IPersonLoader_InsertPerson_10.cs ",
101-
"line": 1
102-
}
103-
10444
],
10545

10646
"ref": "main"

v2/rscg_examples/NativeObjects/description.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"data":{
1212
"goodFor":["Object to IntPtr and back"],
1313
"csprojDemo":"NativeObjectsDemo.csproj",
14-
"csFiles":["Program.cs"],
14+
"csFiles":["Program.cs","Person.cs"],
1515
"excludeDirectoryGenerated":[""],
1616
"includeAdditionalFiles":[""]
1717
},
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Source generator for native interop.
2+
Generates implementation for interfaces to expose managed objects as COM-like, or call methods on COM-like native objects.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# NativeObjects
2+
3+
Source-generator for easier native interop.
4+
5+
It provides two core features:
6+
- Ability to consume COM-like native objects
7+
- Ability to expose managed objects as COM-like native objects
8+
9+
# Usage
10+
11+
**Remember to enable unsafe on your project when referencing this source-generator**
12+
13+
```xml
14+
<PropertyGroup>
15+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
16+
</PropertyGroup>
17+
```
18+
19+
Declare the interface you want to consume or expose, and decorate it with the [NativeObject] attribute:
20+
21+
```csharp
22+
23+
[NativeObject]
24+
public interface ICalculator
25+
{
26+
int Add(int value1, int value2);
27+
}
28+
```
29+
30+
**The order of the methods is used to build the vtable. Therefore you MUST declare the methods in your interface in the same order as the native object.**
31+
32+
From there, you can consume a native object that implements this interface:
33+
34+
```csharp
35+
public int DoSomething(IntPtr nativePtr)
36+
{
37+
var calc = NativeObjects.ICalculator.Wrap(nativePtr);
38+
39+
return calc.Add(2, 3);
40+
}
41+
```
42+
43+
Or implement that interface then expose the managed object to native code:
44+
45+
```csharp
46+
public class MyCalculator : ICalculator
47+
{
48+
public int Add(int value1, int value2)
49+
{
50+
return value1 + value2;
51+
}
52+
}
53+
54+
var calculator = new MyCalculator();
55+
using (var nativeCalculator = NativeObjects.ICalculator.Wrap(calculator))
56+
{
57+
// nativeCalculator can be implicitly cast to IntPtr
58+
// This is equivalent to calling nativeCalculator.Object
59+
SomeNativeCode((IntPtr)nativeCalculator);
60+
}
61+
```
62+
63+
The generated objects have the same visibility as the interface. For instance, if the interface is declared as internal, the generated objects will be internal.
64+
65+
# Namespace
66+
67+
By default, the interop types are emitted in the NativeObjects namespace. You can change it by adding an attribute at the assembly level:
68+
69+
```csharp
70+
[assembly: NativeObjectsNamespace("MyNamespace")]
71+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
{
3+
"$schema": "https://aka.ms/codetour-schema",
4+
"title": "NativeObjects",
5+
"steps":
6+
[
7+
{
8+
"file": "NativeObjectsDemo/NativeObjectsDemo.csproj",
9+
"description": "First, we add Nuget [NativeObjects](https://www.nuget.org/packages/NativeObjects/) in csproj ",
10+
"pattern": "NativeObjects"
11+
}
12+
13+
,{
14+
"file": "NativeObjectsDemo/Program.cs",
15+
"description": "File Program.cs \r\n>> dotnet run --project NativeObjectsDemo/NativeObjectsDemo.csproj ",
16+
"pattern": "this is the code"
17+
}
18+
19+
20+
,{
21+
"file": "NativeObjectsDemo/obj/GX/NativeObjects/NativeObjectGenerator.NativeObjectGenerator/NativeObjectsDemo.IPerson.g.cs",
22+
"description": "Generated File 4 from 4 : NativeObjectsDemo.IPerson.g.cs ",
23+
"line": 1
24+
}
25+
26+
,{
27+
"file": "NativeObjectsDemo/obj/GX/NativeObjects/NativeObjectGenerator.NativeObjectGenerator/NativeObjectsDemo.ICalculator.g.cs",
28+
"description": "Generated File 3 from 4 : NativeObjectsDemo.ICalculator.g.cs ",
29+
"line": 1
30+
}
31+
32+
,{
33+
"file": "NativeObjectsDemo/obj/GX/NativeObjects/NativeObjectGenerator.NativeObjectGenerator/NativeObjectAttribute.g.cs",
34+
"description": "Generated File 2 from 4 : NativeObjectAttribute.g.cs ",
35+
"line": 1
36+
}
37+
38+
,{
39+
"file": "NativeObjectsDemo/obj/GX/NativeObjects/NativeObjectGenerator.NativeObjectGenerator/.ICalculator.g.cs",
40+
"description": "Generated File 1 from 4 : .ICalculator.g.cs ",
41+
"line": 1
42+
}
43+
44+
],
45+
46+
"ref": "main"
47+
48+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"scriptName": "NativeObjects",
3+
"steps":
4+
[
5+
{"typeStep":"exec","arg":"clipchamp.exe launch"},
6+
{"typeStep":"text","arg": "Welcome to Roslyn Examples"},
7+
{"typeStep":"text","arg":"If you want to see more examples , see List Of RSCG"},
8+
{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"},
9+
{"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "},
10+
11+
{"typeStep":"text","arg": "Today I will present NativeObjects . Object to IntPtr and back ."},
12+
{"typeStep":"browser","arg":"https://www.nuget.org/packages/NativeObjects/"},
13+
{"typeStep":"text","arg": "The whole example is here"},
14+
{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects"},
15+
{"typeStep":"text","arg": "You can download the code from here"},
16+
{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects#download-example-net--c-"},
17+
{"typeStep":"text","arg":"Here is the code downloaded "},
18+
{"typeStep":"exec","arg":"explorer.exe /select,D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\NativeObjects\\src\\NativeObjectsDemo.sln"},
19+
{"typeStep":"text","arg": "So , let's start the project with Visual Studio Code "},
20+
{"typeStep":"stepvscode","arg": "-n D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\NativeObjects\\src"},
21+
22+
{"typeStep":"text","arg": "To use it ,you will put the Nuget NativeObjects into the csproj "},
23+
24+
{"typeStep":"stepvscode","arg": "-r -g D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\NativeObjects\\src\\NativeObjectsDemo\\NativeObjectsDemo.csproj"},
25+
26+
{"typeStep":"text","arg": "And now I will show you an example of using NativeObjects"},
27+
28+
{"typeStep":"hide","arg": "now execute the tour in VSCode"},
29+
{"typeStep":"tour", "arg": "src/.tours/"},
30+
{"typeStep":"text","arg":" And I will execute the project"},
31+
{"typeStep":"showproj", "arg":"NativeObjectsDemo.csproj"},
32+
{"typeStep":"text","arg":" This concludes the project"},
33+
{"typeStep":"waitseconds","arg":"30"},
34+
{"typeStep":"text","arg": "Remember, you can download the code from here"},
35+
{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/NativeObjects#download-example-net--c-",
36+
SpeakTest=" "},
37+
{"typeStep":"waitseconds","arg":"30"},
38+
]
39+
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
<h1>EnhancementProject</h1>
22

3-
Number RSCG: 19
3+
Number RSCG: 18
44

55
1 [AutoInvoke.Generator](/docs/AutoInvoke.Generator)
66

77
2 [AutoSpectre](/docs/AutoSpectre)
88

99
3 [BuildInfo](/docs/BuildInfo)
1010

11-
4 [Com](/docs/Com)
11+
4 [CommandLine](/docs/CommandLine)
1212

13-
5 [CommandLine](/docs/CommandLine)
13+
5 [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator)
1414

15-
6 [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator)
15+
6 [Larcanum.GitInfo](/docs/Larcanum.GitInfo)
1616

17-
7 [Larcanum.GitInfo](/docs/Larcanum.GitInfo)
17+
7 [LinqGen.Generator](/docs/LinqGen.Generator)
1818

19-
8 [LinqGen.Generator](/docs/LinqGen.Generator)
19+
8 [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator)
2020

21-
9 [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator)
21+
9 [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator)
2222

23-
10 [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator)
23+
10 [RSCG_AMS](/docs/RSCG_AMS)
2424

25-
11 [RSCG_AMS](/docs/RSCG_AMS)
25+
11 [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram)
2626

27-
12 [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram)
27+
12 [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI)
2828

29-
13 [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI)
29+
13 [RSCG_NameGenerator](/docs/RSCG_NameGenerator)
3030

31-
14 [RSCG_NameGenerator](/docs/RSCG_NameGenerator)
31+
14 [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment)
3232

33-
15 [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment)
33+
15 [RSCG_Wait](/docs/RSCG_Wait)
3434

35-
16 [RSCG_Wait](/docs/RSCG_Wait)
35+
16 [ThisAssembly](/docs/ThisAssembly)
3636

37-
17 [ThisAssembly](/docs/ThisAssembly)
37+
17 [ThisAssembly.Constants](/docs/ThisAssembly.Constants)
3838

39-
18 [ThisAssembly.Constants](/docs/ThisAssembly.Constants)
40-
41-
19 [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata)
39+
18 [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata)
4240

0 commit comments

Comments
 (0)