{"id":13678177,"url":"https://github.com/ful-stackz/SharpCode","last_synced_at":"2025-04-29T12:33:58.426Z","repository":{"id":40399428,"uuid":"296548321","full_name":"ful-stackz/SharpCode","owner":"ful-stackz","description":"Small C# code generator. Easily generate code programmatically!","archived":false,"fork":false,"pushed_at":"2022-07-27T07:42:27.000Z","size":262,"stargazers_count":73,"open_issues_count":4,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-02T13:21:14.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ful-stackz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-09-18T07:35:16.000Z","updated_at":"2024-05-27T13:10:52.000Z","dependencies_parsed_at":"2022-07-12T18:01:55.371Z","dependency_job_id":null,"html_url":"https://github.com/ful-stackz/SharpCode","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ful-stackz%2FSharpCode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ful-stackz%2FSharpCode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ful-stackz%2FSharpCode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ful-stackz%2FSharpCode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ful-stackz","download_url":"https://codeload.github.com/ful-stackz/SharpCode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224173617,"owners_count":17268141,"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":"2024-08-02T13:00:50.801Z","updated_at":"2024-11-11T20:31:10.102Z","avatar_url":"https://github.com/ful-stackz.png","language":"C#","funding_links":[],"categories":["C#"],"sub_categories":[],"readme":"# SharpCode\nSmall C# code generator. Easily generate code programmatically!\n\n[![CI Status](https://img.shields.io/github/workflow/status/ful-stackz/SharpCode/CI?label=CI\u0026logo=github\u0026style=flat)](https://github.com/ful-stackz/SharpCode/actions?query=workflow%3ACI)\n[![Nuget](https://img.shields.io/nuget/v/SharpCode?color=success\u0026label=nuget\u0026logo=nuget\u0026style=flat)](https://www.nuget.org/packages/SharpCode/)\n[![codecov](https://codecov.io/gh/ful-stackz/SharpCode/branch/main/graph/badge.svg?token=F2E4FV2DA3)](https://codecov.io/gh/ful-stackz/SharpCode)\n\n## Install\n\n- .NET CLI `dotnet add package SharpCode`\n- Package Manager `Install-Package SharpCode`\n- Package Reference `\u003cPackageReference Include=\"SharpCode\" Version=\"0.4.0\" /\u003e`\n\n## Usage\n\n\u003cdetails\u003e\n    \u003csummary\u003eSimple usage\u003c/summary\u003e\n\n```csharp\nusing SharpCode;\n\nvar sourceCode = Code.CreateNamespace(\"Data\")\n    .WithClass(Code.CreateClass(\"User\")\n        .WithProperty(Code.CreateProperty(\"int\", \"Id\"))\n        .WithProperty(Code.CreateProperty(\"string\", \"Username\")))\n    .ToSourceCode();\n\nSystem.IO.File.WriteAllText(\"User.cs\", sourceCode);\n\n// User.cs\nnamespace Data\n{\n    public class User\n    {\n        public int Id { get; set; }\n\n        public string Username { get; set; }\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eExtended usage\u003c/summary\u003e\n\n```csharp\nusing SharpCode;\n\nvar dataNamespace = Code.CreateNamespace(\"Data\");\n\nvar userDetailsClass = Code.CreateClass(\"UserDetails\", AccessModifier.Public)\n    .WithField(Code.CreateField(\"int\", \"_id\", AccessModifier.Private).MakeReadonly())\n    .WithField(Code.CreateField(\"string\", \"_username\", AccessModifier.Private).MakeReadonly())\n    .WithConstructor(Code.CreateConstructor()\n        .WithAccessModifier(AccessModifier.Public)\n        .WithParameter(\"int\", \"id\", \"_id\")\n        .WithParameter(\"string\", \"username\", \"_username\"))\n    .WithProperty(Code.CreateProperty(\"int\", \"Id\", AccessModifier.Public)\n        .WithGetter(\"_id\")\n        .WithoutSetter())\n    .WithProperty(Code.CreateProperty(\"string\", \"Username\", AccessModifier.Public)\n        .WithGetter(\"_username\")\n        .WithoutSetter());\n\nvar userClass = Code.CreateClass(\"User\", AccessModifier.Public)\n    .WithProperty(Code.CreateProperty(\"UserDetails\", \"Details\", AccessModifier.Public)\n        .WithoutSetter())\n    .WithConstructor(Code.CreateConstructor()\n        .WithAccessModifier(AccessModifier.Public)\n        .WithParameter(\"UserDetails\", \"details\", \"Details\"));\n\n\nSystem.IO.File.WriteAllText(\n    \"User.cs\",\n    dataNamespace\n        .WithClass(userDetailsClass)\n        .WithClass(userClass)\n        .ToSourceCode());\n\n// User.cs\nnamespace Data\n{\n    public class UserDetails\n    {\n        private readonly int _id;\n        private readonly string _username;\n        public UserDetails(int id, string username)\n        {\n            _id = id;\n            _username = username;\n        }\n\n        public int Id { get =\u003e _id; }\n\n        public string Username { get =\u003e _username; }\n    }\n\n    public class User\n    {\n        public User(UserDetails details)\n        {\n            Details = details;\n        }\n\n        public UserDetails Details { get; }\n    }\n}\n```\n\u003c/details\u003e\n\n## Samples\n\nThe [samples](https://github.com/ful-stackz/SharpCode/tree/main/samples) folder contains sample projects which make use of `SharpCode`. The projects are fully functional\nand can be played around with. Check the `samples/README.md` for more information.\n\n## Features\n\nWith `SharpCode` you can programmatically generate source code for a lot of C# structures. When generating the source\ncode of any structure `SharpCode` performs basic validation to ensure a level of correctness of the produced source\ncode.\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerating namespace source code\u003c/summary\u003e\n\n```csharp\n// ✔ Define the name of the namespace\nnamespace Data\n{\n    // ✔ Interface members with different access modifiers\n    public interface IHasData {}\n\n    // ✔ Class members with different access modifiers\n    public class Data {}\n\n    // ✔ Struct members with different access modifiers\n    public struct DataPoint {}\n\n    // ✔ Enum members with different access modifiers\n    public enum DataType {}\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerating interface source code\u003c/summary\u003e\n\n```csharp\n// ✔ Define XML summary docs\n// ✔ Define the name of the interface\n// ✔ Define a list of implemented interfaces\n/// \u003csummary\u003e\n/// Docs!\n/// \u003c/summary\u003e\npublic interface IHasData : IImplementedInterface\n{\n    // ✔ Define property members\n    int Count { get; set; }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerating class source code\u003c/summary\u003e\n\n```csharp\n// ✔ Define XML summary docs\n// ✔ Define the name of the class\n// ✔ Define an inherited class\n// ✔ Define a list of implemented interfaces\n/// \u003csummary\u003e\n/// Docs!\n/// \u003c/summary\u003e\npublic class Data : DataBase, IHasData\n{\n    // ✔ Define field members\n    private int _count;\n\n    // ✔ Define constructors\n    // ✔ Define constructor XML summary docs\n    // ✔ Define constructor parameters\n    // ✔ Define accepting fields for constructor parameters\n    // ✔ Define base calls with parameters\n    /// \u003csummary\u003e\n    /// Docs!\n    /// \u003c/summary\u003e\n    public Data(int count) : DataBase(count)\n    {\n        _count = count;\n    }\n\n    // ✔ Define property members\n    // ✔ Define property XML summary docs\n    // ✔ Define custom getter/setter for properties\n    /// \u003csummary\u003e\n    /// Docs!\n    /// \u003c/summary\u003e\n    public int Count { get =\u003e _count; set =\u003e _count = value; }\n\n    // ✔ Define auto-implemented properties\n    public string Name { get; set; }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerating struct source code\u003c/summary\u003e\n\n```csharp\n// ✔ Define XML summary docs\n// ✔ Define the name of the struct\n// ✔ Define a list of implemented interfaces\n/// \u003csummary\u003e\n/// Docs!\n/// \u003c/summary\u003e\npublic struct DataPoint : IHasData\n{\n    // ✔ Define field members\n    private int _count;\n\n    // ✔ Define constructors\n    // ✔ Define constructor XML summary docs\n    // ✔ Define constructor parameters\n    // ✔ Define accepting fields for constructor parameters\n    /// \u003csummary\u003e\n    /// Docs!\n    /// \u003c/summary\u003e\n    public Data(int count)\n    {\n        _count = count;\n    }\n\n    // ✔ Define property members\n    // ✔ Define property XML summary docs\n    // ✔ Define custom getter/setter for properties\n    /// \u003csummary\u003e\n    /// Docs!\n    /// \u003c/summary\u003e\n    public int Count { get =\u003e _count; set =\u003e _count = value; }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerating enum source code\u003c/summary\u003e\n\n```csharp\n// ✔ Define XML summary docs\n// ✔ Define the name of the enum\n/// \u003csummary\u003e\n/// Docs!\n/// \u003c/summary\u003e\npublic enum DataType\n{\n    // ✔ Define enum members\n    // ✔ Define XML summary docs for enum members\n    // ✔ Define explicit values for enum members\n    /// \u003csummary\u003e\n    /// Docs!\n    /// \u003c/summary\u003e\n    Invalid = 0,\n    Incomplete,\n    Complete,\n}\n```\n\n```csharp\n// ✔ Define enum as flags\n// ✔ Auto generated flags-compatible values for enum members\n[System.Flags]\npublic enum ExampleFlags\n{\n    None = 0,\n    A = 1,\n    B = 2,\n    C = 4,\n    D = 8,\n}\n```\n\u003c/details\u003e\n\n## Development\n\nYou don't need anything special for local development.\n\n- `dotnet build ./src/SharpCode` - will build you your own local `SharpCode`\n- `dotnet add \u003cpath to your project\u003e reference \u003cpath to ./src/SharpCode\u003e` - will add `SharpCode` as a local reference to your project\n- `dotnet test ./src/SharpCode.Test` - will run the tests\n- `dotnet watch test ./src/SharpCode.Test` - will run the tests everytime you make a change to the source code\nof `SharpCode` itself or the tests\n\n## Contributing\n\nThis library is still in its early stages and being figured out. Many changes are expected and incoming. For your own\nsake please don't work on any big changes as the files might disappear before you're ready.\n\nNonetheless, insights into the usage of the library, structure and general suggestions are always welcome! Thank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fful-stackz%2FSharpCode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fful-stackz%2FSharpCode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fful-stackz%2FSharpCode/lists"}