{"id":26999451,"url":"https://github.com/kevingosse/NativeObjects","last_synced_at":"2025-04-04T03:02:26.233Z","repository":{"id":269336951,"uuid":"907056040","full_name":"kevingosse/NativeObjects","owner":"kevingosse","description":"Source-generator for easier native interop.","archived":false,"fork":false,"pushed_at":"2025-02-02T19:27:35.000Z","size":23,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T10:04:08.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevingosse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-22T17:27:52.000Z","updated_at":"2025-03-18T06:51:53.000Z","dependencies_parsed_at":"2024-12-22T20:37:09.060Z","dependency_job_id":"d8aeaf9d-442f-41e7-82ca-ec5fe452680d","html_url":"https://github.com/kevingosse/NativeObjects","commit_stats":null,"previous_names":["kevingosse/nativeobjects"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevingosse%2FNativeObjects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevingosse%2FNativeObjects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevingosse%2FNativeObjects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevingosse%2FNativeObjects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevingosse","download_url":"https://codeload.github.com/kevingosse/NativeObjects/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247112739,"owners_count":20885606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-04T03:01:34.236Z","updated_at":"2025-04-04T03:02:26.222Z","avatar_url":"https://github.com/kevingosse.png","language":"C#","funding_links":[],"categories":["Content"],"sub_categories":["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"],"readme":"# NativeObjects\n\nSource-generator for easier native interop.\n\nIt provides two core features:\n- Ability to consume COM-like native objects\n- Ability to expose managed objects as COM-like native objects\n\n# Usage\n\n**Remember to enable unsafe on your project when referencing this source-generator**\n\n```xml\n\u003cPropertyGroup\u003e\n    \u003cAllowUnsafeBlocks\u003etrue\u003c/AllowUnsafeBlocks\u003e\n\u003c/PropertyGroup\u003e\n```\n\nDeclare the interface you want to consume or expose, and decorate it with the [NativeObject] attribute:\n\n```csharp\n\n[NativeObject]\npublic interface ICalculator\n{\n    int Add(int value1, int value2);\n}\n```\n\n**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.**\n\nFrom there, you can consume a native object that implements this interface:\n\n```csharp\npublic int DoSomething(IntPtr nativePtr)\n{\n    var calc = NativeObjects.ICalculator.Wrap(nativePtr);\n\n    return calc.Add(2, 3);\n}\n```\n\nOr implement that interface then expose the managed object to native code:\n\n```csharp\npublic class MyCalculator : ICalculator\n{\n    public int Add(int value1, int value2)\n    {\n        return value1 + value2;\n    }\n}\n\nvar calculator = new MyCalculator();\nusing (var nativeCalculator = NativeObjects.ICalculator.Wrap(calculator))\n{\n    // nativeCalculator can be implicitly cast to IntPtr\n    // This is equivalent to calling nativeCalculator.Object\n    SomeNativeCode((IntPtr)nativeCalculator);\n}\n```\n\nThe generated objects have the same visibility as the interface. For instance, if the interface is declared as internal, the generated objects will be internal.\n\n# Namespace\n\nBy default, the interop types are emitted in the NativeObjects namespace. You can change it by adding an attribute at the assembly level:\n\n```csharp\n[assembly: NativeObjectsNamespace(\"MyNamespace\")]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevingosse%2FNativeObjects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevingosse%2FNativeObjects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevingosse%2FNativeObjects/lists"}