$ show GtkSharp/GtkSharp
GtkSharp is a set of C# language bindings for the GTK graphical user interface library and its associated components (GLib, GDK, Cairo, Pango, ATK, GIO, WebKit). It provides a .NET API that wraps native GObject-based libraries using dynamic function loading and manual marshaling. The repository includes a code generation tool (GapiCodegen) that parses XML API descriptions to produce partial C# classes, which are then extended with hand-written customizations for convenience constructors, properties, and signal handling. The bindings target .NET Standard 2.0 and are packaged as NuGet packages. The repository also contains sample applications, project templates for C#, F#, and VB.NET, a MonoDevelop addin for scaffolding, and a .NET SDK workload for project creation. The codebase demonstrates a comprehensive binding pattern with runtime function resolution, ABI struct handling, and GLib main loop integration. However, it shows signs of technical drift with many deprecated API markers, platform-specific workarounds, and legacy code in the OldStuff directory.
The LLM identified 3 files worth highlighting for reuse:
Provides a cross-platform mechanism to dynamically load native shared libraries (dlopen/dlsym on Linux/macOS, LoadLibrary/GetProcAddress on Windows) and resolve function pointers at runtime. This is the foundational FFI layer for all GtkSharp bindings, enabling the C# code to call C functions without compile-time linking. The class is self-contained and could be extracted for any project needing runtime native method loading.
Implements a thread-safe mechanism to schedule a callback on the main GLib event loop from any thread. Uses a lock and a flag to ensure the idle callback is added only once, preventing duplicate registrations. This pattern is reusable for any application that needs to marshal work from background threads to a single-threaded event loop, common in GUI and game frameworks.
A standalone, well-documented command-line option parser similar to NDesk.Options. Supports typed actions (bool, int, string, float), aliases, option bundling, and response files. It is used by the GapiCodegen tool but is completely self-contained and could be reused in any .NET CLI application. Demonstrates clean separation of parsing logic from application code.