{"id":17948220,"url":"https://github.com/hez2010/typedocconverter","last_synced_at":"2025-03-24T22:35:24.389Z","repository":{"id":41181648,"uuid":"236150304","full_name":"hez2010/TypedocConverter","owner":"hez2010","description":"This is a typedoc json to C# type bindings converter. Can be used as a TypeScript to C# bindings converter.","archived":false,"fork":false,"pushed_at":"2023-03-29T15:00:54.000Z","size":983,"stargazers_count":113,"open_issues_count":2,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T09:02:54.403Z","etag":null,"topics":["bindings-converter","codegen","csharp","dotnet","fsharp","typedoc","typescript"],"latest_commit_sha":null,"homepage":"","language":"F#","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/hez2010.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}},"created_at":"2020-01-25T09:34:58.000Z","updated_at":"2024-10-01T11:03:19.000Z","dependencies_parsed_at":"2023-01-30T05:30:34.150Z","dependency_job_id":null,"html_url":"https://github.com/hez2010/TypedocConverter","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hez2010%2FTypedocConverter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hez2010%2FTypedocConverter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hez2010%2FTypedocConverter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hez2010%2FTypedocConverter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hez2010","download_url":"https://codeload.github.com/hez2010/TypedocConverter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245366205,"owners_count":20603438,"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":["bindings-converter","codegen","csharp","dotnet","fsharp","typedoc","typescript"],"created_at":"2024-10-29T09:02:59.505Z","updated_at":"2025-03-24T22:35:19.377Z","avatar_url":"https://github.com/hez2010.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typedoc Converter\nThis is a [typedoc](https://github.com/TypeStrong/typedoc) json to C# bindings converter. Can be used as a TypeScript to C# bindings converter. \n\nBuild status: ![.NET](https://github.com/hez2010/TypedocConverter/workflows/.NET/badge.svg)\n\n## Compatibility Status\n- typedoc: 0.20\n- TypeScript: 3.9, 4.0, 4.1, 4.2\n\n## Languages support\n- [x] Enums\n  - [x] Direct value\n  - [x] Referenced value\n- [x] Interfaces\n  - [x] Inherits\n  - [x] Generics\n  - [ ] Generics Constaints\n  - [x] Properties\n  - [x] Methods\n  - [x] Events\n- [x] Classes\n  - [x] Constructors\n  - [x] Inherits\n  - [x] Generics\n  - [ ] Generics Constaints\n  - [x] Properties\n  - [x] Methods\n  - [x] Events\n  - [x] Indexer\n- [ ] Types\n  - [x] String literals\n  - [x] Type literals\n  - [x] Type alias*\n  - [x] Union types\n  - [ ] Intersection types\n- [x] Split entities to different files\n- [x] Auto rename conflict parameter names\n- [x] WinRT/CLR async types support (`IAsyncAction`/`IAsyncOperation\u003cT\u003e` or `Task`/`Task\u003cT\u003e`)\n- [x] Newtonsoft.Json and System.Text.Json for JSON serialization\n- [x] Nullable Reference Types\n- [ ] Type validation\n\n`*: Partial support`\n\n## Installation\n```\ndotnet tool install -g TypedocConverter\n```\n\n## Quick start\nTypeScript code `input.ts`:\n```typescript\ndeclare namespace test {\n  /**\n   * The declaration of an enum\n   */\n  export enum MyEnum {\n    A = 0,\n    B = 1,\n    C = 2,\n    D = C\n  }\n\n  /**\n   * The declaration of an interface\n   */\n  export interface MyInterface1 {\n    /**\n     * A method\n     */\n    testMethod(arg: string, callback: () =\u003e void): string;\n    /**\n     * An event\n     * @event\n     */\n    onTest(listener: (e: MyInterface1) =\u003e void): void;\n    /**\n     * An property\n     */\n    readonly testProp: string;\n  }\n\n  /**\n   * Another declaration of an interface\n   */\n  export interface MyInterface2\u003cT\u003e {\n    /**\n     * A method\n     */\n    testMethod(arg: T, callback: () =\u003e void): T;\n    /**\n     * An event\n     * @event\n     */\n    onTest(listener: (e: MyInterface2\u003cT\u003e) =\u003e void): void;\n    /**\n     * An property\n     */\n    readonly testProp: T;\n  }\n\n  /**\n   * The declaration of a class\n   */\n  export class MyClass1\u003cT\u003e implements MyInterface1 {\n    /**\n     * A method\n     */\n    testMethod(arg: string, callback: () =\u003e void): string;\n    /**\n     * An event\n     * @event\n     */\n    onTest(listener: (e: MyInterface1) =\u003e void): void;\n    /**\n     * An property\n     */\n    readonly testProp: string;\n    static staticMethod(value: string, isOption?: boolean): UnionStr;\n  }\n\n  /**\n   * Another declaration of a class\n   */\n  export class MyClass2\u003cT\u003e implements MyInterface2\u003cT\u003e {\n    /**\n     * A method\n     */\n    testMethod(arg: T, callback: () =\u003e void): T;\n    /**\n     * An event\n     * @event\n     */\n    onTest(listener: (e: MyInterface2\u003cT\u003e) =\u003e void): void;\n    /**\n     * An property\n     */\n    readonly testProp: T;\n    static staticMethod(value: string, isOption?: boolean): UnionStr;\n  }\n\n  /**\n   * The declaration of a type alias\n   */\n  export type UnionStr = \"A\" | \"B\" | \"C\" | \"other\";\n}\n```\n\nWith below commands (need a `tsconfig.json`): \n```bash\ntypedoc input.ts --json output.json\nTypedocConverter --inputfile output.json --outputfile output.cs\n```\n\nVoila! C# type bindings generated in output.cs:\n```csharp\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// The declaration of an enum\n    /// \u003c/summary\u003e\n    enum MyEnum\n    {\n        A = 0,\n        B = 1,\n        C = 2,\n        D = 2\n    }\n}\n\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// The declaration of a class\n    /// \u003c/summary\u003e\n    class MyClass1\u003cT\u003e : MyInterface1\n    {\n        /// \u003csummary\u003e\n        /// An event\n        /// \u003c/summary\u003e\n        public event System.Action\u003cMyInterface1\u003e OnTest;\n\n        /// \u003csummary\u003e\n        /// An property\n        /// \u003c/summary\u003e\n        [Newtonsoft.Json.JsonProperty(\"testProp\", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]\n        public string TestProp { get =\u003e throw new System.NotImplementedException(); set =\u003e throw new System.NotImplementedException(); }\n\n        /// \u003csummary\u003e\n        /// A method\n        /// \u003c/summary\u003e\n        public string TestMethod(string arg, System.Action callback) =\u003e throw new System.NotImplementedException();\n\n        static UnionStr StaticMethod(string value, bool isOption) =\u003e throw new System.NotImplementedException();\n\n    }\n}\n\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// Another declaration of a class\n    /// \u003c/summary\u003e\n    class MyClass2\u003cT\u003e : MyInterface2\u003cT\u003e\n    {\n        /// \u003csummary\u003e\n        /// An event\n        /// \u003c/summary\u003e\n        public event System.Action\u003cMyInterface2\u003cT\u003e\u003e OnTest;\n\n        /// \u003csummary\u003e\n        /// An property\n        /// \u003c/summary\u003e\n        [Newtonsoft.Json.JsonProperty(\"testProp\", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]\n        public T TestProp { get =\u003e throw new System.NotImplementedException(); set =\u003e throw new System.NotImplementedException(); }\n\n        /// \u003csummary\u003e\n        /// A method\n        /// \u003c/summary\u003e\n        public T TestMethod(T arg, System.Action callback) =\u003e throw new System.NotImplementedException();\n\n        static UnionStr StaticMethod(string value, bool isOption) =\u003e throw new System.NotImplementedException();\n\n    }\n}\n\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// The declaration of an interface\n    /// \u003c/summary\u003e\n    interface MyInterface1\n    {\n        /// \u003csummary\u003e\n        /// An event\n        /// \u003c/summary\u003e\n        event System.Action\u003cMyInterface1\u003e OnTest;\n\n        /// \u003csummary\u003e\n        /// An property\n        /// \u003c/summary\u003e\n        [Newtonsoft.Json.JsonProperty(\"testProp\", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]\n        string TestProp { get; set; }\n\n        /// \u003csummary\u003e\n        /// A method\n        /// \u003c/summary\u003e\n        string TestMethod(string arg, System.Action callback);\n\n    }\n}\n\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// Another declaration of an interface\n    /// \u003c/summary\u003e\n    interface MyInterface2\u003cT\u003e\n    {\n        /// \u003csummary\u003e\n        /// An event\n        /// \u003c/summary\u003e\n        event System.Action\u003cMyInterface2\u003cT\u003e\u003e OnTest;\n\n        /// \u003csummary\u003e\n        /// An property\n        /// \u003c/summary\u003e\n        [Newtonsoft.Json.JsonProperty(\"testProp\", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]\n        T TestProp { get; set; }\n\n        /// \u003csummary\u003e\n        /// A method\n        /// \u003c/summary\u003e\n        T TestMethod(T arg, System.Action callback);\n\n    }\n}\n\nnamespace Test\n{\n\n    /// \u003csummary\u003e\n    /// The declaration of a type alias\n    /// \u003c/summary\u003e\n    [Newtonsoft.Json.JsonConverter(typeof(UnionStrConverter))]\n    enum UnionStr\n    {\n        ///\u003csummary\u003e\n        /// A\n        ///\u003c/summary\u003e\n        A,\n        ///\u003csummary\u003e\n        /// B\n        ///\u003c/summary\u003e\n        B,\n        ///\u003csummary\u003e\n        /// C\n        ///\u003c/summary\u003e\n        C,\n        ///\u003csummary\u003e\n        /// other\n        ///\u003c/summary\u003e\n        Other\n    }\n\n    class UnionStrConverter : Newtonsoft.Json.JsonConverter\n    {\n        public override bool CanConvert(System.Type t) =\u003e t == typeof(UnionStr) || t == typeof(UnionStr?);\n\n        public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type t, object? existingValue, Newtonsoft.Json.JsonSerializer serializer)\n            =\u003e reader.TokenType switch\n            {\n                Newtonsoft.Json.JsonToken.String =\u003e\n                    serializer.Deserialize\u003cstring\u003e(reader) switch\n                    {\n                        \"A\" =\u003e UnionStr.A,\n                        \"B\" =\u003e UnionStr.B,\n                        \"C\" =\u003e UnionStr.C,\n                        \"other\" =\u003e UnionStr.Other,\n                        _ =\u003e throw new System.NotSupportedException(\"Cannot unmarshal type UnionStr\")\n                    },\n                _ =\u003e throw new System.NotSupportedException(\"Cannot unmarshal type UnionStr\")\n            };\n\n        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object? untypedValue, Newtonsoft.Json.JsonSerializer serializer)\n        {\n            if (untypedValue is null) { serializer.Serialize(writer, null); return; }\n            var value = (UnionStr)untypedValue;\n            switch (value)\n            {\n                case UnionStr.A: serializer.Serialize(writer, \"A\"); return;\n                case UnionStr.B: serializer.Serialize(writer, \"B\"); return;\n                case UnionStr.C: serializer.Serialize(writer, \"C\"); return;\n                case UnionStr.Other: serializer.Serialize(writer, \"other\"); return;\n                default: break;\n            }\n            throw new System.NotSupportedException(\"Cannot marshal type UnionStr\");\n        }\n    }\n}\n```\n\n\n## Build\n```bash\ncd TypedocConverter/TypedocConverter\ndotnet publish -c Release -r win-x64 --no-self-contained /p:PublishSingleFile=true /p:PublishReadyToRun=true\n```\nYou can replace `win-x64` with other platform identifiers such as `win-arm64`, `linux-x64`, `linux-arm64`, `osx-x64` and etc.  \nThen built dists will be placed in `bin/Release/net7.0/[platform identifier]/publish`\n\n## Native Build\n```bash\ncd TypedocConverter/TypedocConverter\ndotnet publish -c Release -r win-x64 /p:PublishAot=true\n```\nYou can replace `win-x64` with other platform identifiers such as `win-arm64`, `linux-x64`, `linux-arm64`, `osx-x64` and etc.  \nThen built dists will be placed in `bin/Release/net7.0/[platform identifier]/publish`\n\n## Run \u0026 Usage\n```bash\nTypedocConverter --help\n```\nSample:\n```bash\nTypedocConverter --inputfile 1.json --splitfiles true --outputdir .\n```\nArguments:\n```\n--inputfile [file]: input file\n--namespace [namespace]: specify namespace for generated code\n--splitfiles [true|false]: whether to split code to different files\n--outputdir [path]: used for place code files when splitfiles is true\n--outputfile [path]: used for place code file when splitfiles is false\n--number-type [int/decimal/double...]: config for number type mapping\n--promise-type [CLR/WinRT]: config for promise type mapping, CLR for Task and WinRT for IAsyncAction/IAsyncOperation\n--any-type [object/dynamic...]: config for any type mapping\n--array-type [Array/IEnumerable/List...]: config for array type mapping\n--nrt-disabled [true|false]: whether to disable Nullable Reference Types\n--json-mode [system|newtonsoft|both]: whether to use System.Text.Json or Newtonsoft.Json or both\n```\n\n## Prebuilt binaries\nWe have prepared some prebuilt binaries for Windows, Linux and macOS.  \nYou can download them directly from [Releases](https://github.com/hez2010/TypedocConverter/releases)\n\nPrerequisites: [.NET Runtime 7.0](https://dotnet.microsoft.com/download/dotnet-core/7.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhez2010%2Ftypedocconverter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhez2010%2Ftypedocconverter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhez2010%2Ftypedocconverter/lists"}