mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-08 11:56:41 +00:00
feat(dotnet): add "magic methods" notes
This commit is contained in:
parent
a4334b5f05
commit
0bca4bd4ab
1 changed files with 12 additions and 15 deletions
|
@ -2922,22 +2922,19 @@ In this case, the method must also be declared as `static`.
|
||||||
private static extern void AVIFileInit();
|
private static extern void AVIFileInit();
|
||||||
```
|
```
|
||||||
|
|
||||||
The `LibraryImport` attribute can be used to import external code and have the source generator handle the marshalling for the annotated function.
|
## Magic Methods
|
||||||
|
|
||||||
> **Note**: The source generator will still use the `DllImport` attribute in the generated code.
|
Methods needed to implement a behaviour which do not need an interface to work. The methods **must** be named _appropriately_ and have the correct _return type_.
|
||||||
|
|
||||||
|
### Enumerable
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
// before
|
public bool MoveNext(/* ... */);
|
||||||
public static class Native
|
public T Current { get; }
|
||||||
{
|
```
|
||||||
[DllImport(nameof(Native), CharSet = CharSet.Unicode)]
|
|
||||||
public extern static string ToLower(string str);
|
### Awaitable
|
||||||
}
|
|
||||||
|
```cs
|
||||||
// after
|
public TaskAwaiter GetAwaiter(/* ... */);
|
||||||
public static class Native
|
|
||||||
{
|
|
||||||
[LibraryImport(nameof(Native), StringMarshalling = StringMarshalling.Utf16)]
|
|
||||||
public static partial string ToLower(string str);
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue