2024-12-04 TIL

2024-12-04 TIL: P/Invoke, C# Iterators, Cross-Platform WPF, and ‘Dulce Domum’

💻

P/Invoke

Ever needed to call native functions from a DLL in your .NET app? P/Invoke (Platform Invoke) bridges the gap between managed and unmanaged code.

  • Managed Code: Runs under the control of the .NET runtime (e.g., C#).
  • Unmanaged Code: Runs outside the .NET runtime (e.g., C/C++ native libraries).

Key Ingredients for P/Invoke:

  1. DllImport Attribute: Declares the external method and specifies the DLL.
  2. Marshaling: Automatically converts between managed (C#) and unmanaged (native) types.
  3. System.Runtime.InteropServices: Provides tools for defining P/Invoke signatures and managing interop behavior.

yield

In C#, the yield keyword simplifies the creation of iterators, enabling methods to return elements of a collection one at a time without the overhead of creating temporary collections or implementing complex iterator logic.

  • Deferred Execution: Using yield return, a method can produce each element only when it’s needed during iteration.
  • State Preservation: The method retains its execution state between yield return calls, allowing it to resume from where it left off in subsequent iterations.

LINQPad

The Ultimate Scratchpad for C#

  • LINQPad comes with an integrated tutorial/reference, comprising interactive sample queries.

Avalonia XPF

A cross-platform WPF that enables you to reuse your code and extend your app’s reach.

  • Avalonia XPF enables WPF apps to run on macOS and Linux with Avalonia’s Fork of WPF, which allows Avalonia to maintain both API and binary compatibility with WPF. Avalonia XPF replaces the low-level WPF code (MilCore) with Avalonia.
  • Avalonia XPF is based on WPF shipped with .NET 6.0 SDK. Currently, unsupported WPF features include Visual3D, Viewport3D, InkCanvas, Win32 interop, and custom Window chromes.

🌱

趿

tā, walk in slippers.

  • 趿拉:把鞋后帮踩在脚后跟下
  • 趿拉板儿:wooden slippers

Dulce Domum

Dulce Domum (lit. Sweetly Homeward) is a tune composed by Robert Ambrose in 1876. This phrase is used as the title of chapter 5 of the 1908 novel The Wind in the Willows.

  • lit. is an abbreviation for “literal” or “literally”.
Puran Zhang @puran