Skip to content

Commit b0a90fc

Browse files
committed
Readme + xmldocs in sample
1 parent d57d204 commit b0a90fc

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ TypeShim generates strongly-typed interop code for both C# & TypeScript, tailore
2020
- 👍 [Easy setup](#installing)
2121

2222
## Samples
23-
Samples below demonstrate the same operations when interfacing with TypeShim generated code vs `JSExport` generated code. Either way you will load your wasm browser app as [described in the docs](https://learn.microsoft.com/en-us/aspnet/core/client-side/dotnet-interop/wasm-browser-app?view=aspnetcore-10.0#javascript-interop-on-). The runtime created by `dotnet.create()` can be passed directly into the provided `TypeShimInitializer`'s `initialize` method. The initializer exists so that helper functions for type marshalling can be set up and a reference to the assembly exports can be retrieved for the generated types to use internally.
23+
24+
[Check out the sample project](https://github.com/ArcadeMode/TypeShim/blob/master/sample/README.md) to see TypeShim in action. The snippets below also give a general idea of its capabilities.
25+
26+
The snippets compare TypeShim vs manual `JSExport`. Whichever you use, you'll have load your wasm browser app as [described in the docs](https://learn.microsoft.com/en-us/aspnet/core/client-side/dotnet-interop/wasm-browser-app?view=aspnetcore-10.0#javascript-interop-on-). The runtime created by `dotnet.create()` can be passed directly into the provided `TypeShimInitializer`'s `initialize` method. The initializer exists so that helper functions for type marshalling can be set up and a reference to the assembly exports can be retrieved for the generated types to use internally.
2427

2528
### TypeShim
2629
A simple example where we have an app about 'people', just to show basic language use powered by TypeShim.
@@ -95,14 +98,12 @@ public async UsingTypeShim() {
9598
```
9699

97100
#### 'Raw' JSExport
98-
Here you can see a quick demonstration of roughly the same behavior as the TypeShim sample, with handwritten JSExport. Certain parts enabled by TypeShim have not been replicated as the point may be clear at a glance: this is a large amount of difficult to maintain boilerplate if you have to write it yourself.
101+
Here you can see a quick demonstration of roughly the same behavior as the TypeShim sample, with handwritten JSExport. Certain parts enabled by TypeShim have not been replicated as the point may be clear at a glance: this is a large amount of difficult to maintain boilerplate if you have to write it yourself. The regression sensitivity of such code may also be noted.
99102

100103
<details>
101104
<summary>See the 'Raw' <code>JSExport</code> implementation</summary>
102105
&nbsp;
103106

104-
Note the error sensitivity of passing untyped objects across the interop boundary.
105-
106107
```ts
107108
public async UsingRawJSExport(exports: any) {
108109
const runtime = await dotnet.withApplicationArguments(args).create();

sample/Library/Models.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,46 @@ public class People()
1010
public required Person[] All { get; set; }
1111
}
1212

13+
/// <summary>
14+
/// Represents a person with a unique identifier, name, age, and a collection of owned pets.
15+
/// </summary>
16+
/// <remarks>The Pets property contains an array of Dog objects that represent the pets currently owned by the
17+
/// person. The Person class provides methods to compare ages with another person and to adopt new pets.
18+
/// </remarks>
1319
[TSExport]
1420
public class Person
1521
{
22+
23+
// this class has a few comments,
24+
// To demonstrate that these will reflect in the generated TypeScript code
25+
// as documentation for the properties and methods of the Person class!
26+
27+
/// <summary>
28+
/// Comments work <i>including formatting</i>
29+
/// <list type="bullet">
30+
/// <item><description>Even</description></item>
31+
/// <item><description>Lists</description></item>
32+
/// <item><description><b>Work!</b></description></item>
33+
/// </list>
34+
/// </summary>
1635
public required int Id { get; set; }
1736
public required string Name { get; set; }
1837
public required int Age { get; set; }
1938
public required Dog[] Pets { get; set; }
2039

40+
/// <summary>
41+
/// Checks if this person is older than another person.
42+
/// </summary>
43+
/// <param name="other">Another person</param>
44+
/// <returns>True if this person is older than the other person, otherwise false</returns>
2145
public bool IsOlderThan(Person other)
2246
{
2347
return Age > other.Age;
2448
}
2549

50+
/// <summary>
51+
/// Adopts a <b>new pet</b> for this person.
52+
/// </summary>
2653
public void AdoptPet()
2754
{
2855
RandomEntityGenerator generator = new();

0 commit comments

Comments
 (0)