{"id":30326106,"url":"https://github.com/inosik/fable-csharp-import-sample","last_synced_at":"2025-08-17T23:09:14.665Z","repository":{"id":63906151,"uuid":"109507099","full_name":"inosik/fable-csharp-import-sample","owner":"inosik","description":"A sample that shows how to create bindings for Fable projects with C# or any other .NET language.","archived":false,"fork":false,"pushed_at":"2022-11-28T17:56:33.000Z","size":94,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-30T18:21:53.084Z","etag":null,"topics":["csharp","fable","fsharp"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inosik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-04T15:36:23.000Z","updated_at":"2023-11-23T15:12:16.000Z","dependencies_parsed_at":"2022-11-28T19:52:08.566Z","dependency_job_id":null,"html_url":"https://github.com/inosik/fable-csharp-import-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inosik/fable-csharp-import-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inosik%2Ffable-csharp-import-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inosik%2Ffable-csharp-import-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inosik%2Ffable-csharp-import-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inosik%2Ffable-csharp-import-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inosik","download_url":"https://codeload.github.com/inosik/fable-csharp-import-sample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inosik%2Ffable-csharp-import-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270918404,"owners_count":24667679,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["csharp","fable","fsharp"],"created_at":"2025-08-17T23:09:12.946Z","updated_at":"2025-08-17T23:09:14.654Z","avatar_url":"https://github.com/inosik.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fable Bindings With C\\#\n\nThis is a sample which shows that we can create bindings for Fable projects with C# or any other .NET language.\n\n## Background\n\nAs we only want to provide metadata from our assembly, we can do it with any .NET language. As long as we decorate our classes and methods with the `Import` attribute from the Fable.Core package, Fable knows what `import` statements it needs to generate. However, if we wanted to provide more than simple typed bindings, this approach won't work anymore, because Fable then would need the source code of the extra functionality, which had to be F#.\n\nThis might be useful if we wanted to reuse [Retyped][retyped] bindings with Fable.\n\n  [retyped]: https://retyped.com\n\n## Why C\\#?\n\nI noticed that with the `extern` keyword, we can build really nice bindings for JavaScript packages. However, `extern` is somewhat limited and hard to use in F#. It can only be used with functions, and the syntax switches to a C-like style when creating such functions. In C# however, `extern` can be put on pretty much everything: instance methods, static methods, properties and even constructors!\n\nBindings for JavaScript classes, for example, become really straight forward to write for authors:\n\n``` csharp\n[Fable.Core.Global]\npublic class XMLHttpRequest\n{\n  public extern XMLHttpRequest();\n  public extern void send();\n}\n```\n\nAnd easy to use for users:\n\n``` fsharp\nlet req = XMLHttpRequest ()\nreq.send ()\n```\n\n## Instructions\n\nFollow these steps:\n\n``` shell\n# Restore the packages\ndotnet tool restore\ndotnet restore\nnpm install\n\n# Prepare the bindings\n# Unfortunately, project references don't work here\ndotnet build -o bindings Fable.Import.LeftPad/\ndotnet build -o bindings Fable.Import.Node/\n\n# Compile to JavaScript\ndotnet fable Sample/ --outDir js\n\n# Run the sample application\nnode .\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finosik%2Ffable-csharp-import-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finosik%2Ffable-csharp-import-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finosik%2Ffable-csharp-import-sample/lists"}