{"id":15036246,"url":"https://github.com/ryotamurohoshi/valueobjectgenerator","last_synced_at":"2026-03-17T03:32:35.129Z","repository":{"id":79723811,"uuid":"309730226","full_name":"RyotaMurohoshi/ValueObjectGenerator","owner":"RyotaMurohoshi","description":"ValueObjectGenerator is Generator for ValueObjects.","archived":false,"fork":false,"pushed_at":"2020-11-30T12:08:05.000Z","size":14,"stargazers_count":41,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T01:11:45.547Z","etag":null,"topics":["csharp","csharp-library","csharp-sourcegenerator"],"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/RyotaMurohoshi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-03T15:33:10.000Z","updated_at":"2025-03-19T18:00:52.000Z","dependencies_parsed_at":"2023-02-28T02:31:12.579Z","dependency_job_id":null,"html_url":"https://github.com/RyotaMurohoshi/ValueObjectGenerator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaMurohoshi%2FValueObjectGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaMurohoshi%2FValueObjectGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaMurohoshi%2FValueObjectGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaMurohoshi%2FValueObjectGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyotaMurohoshi","download_url":"https://codeload.github.com/RyotaMurohoshi/ValueObjectGenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126381,"owners_count":21051911,"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":["csharp","csharp-library","csharp-sourcegenerator"],"created_at":"2024-09-24T20:30:37.071Z","updated_at":"2026-03-17T03:32:35.054Z","avatar_url":"https://github.com/RyotaMurohoshi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ValueObjectGenerator\n\n`ValueObjectGenerator` is C# source generator is for ValueObjects (ie.Wrapper classes).\n\nThis project is under the develop🚧.\n\n## Install\n\nUnder the develop.\n\n## Usage\n\n```csharp\nusing ValueObjectGenerator;\n\n[IntValueObject]\npublic partial class ProductId\n{\n}\n```\n\nWith `IntValueObject` attribute, below code is generated.\n\n```csharp\npublic partial class ProductId: IEquatable\u003cProductId\u003e\n{\n    public int Value { get; }\n\n    public ProductId(int value)\n    {\n        Value = value;\n    }\n\n    public override bool Equals(object obj) =\u003e ReferenceEquals(this, obj) || obj is ProductId other \u0026\u0026 Equals(other);\n    public override int GetHashCode() =\u003e Value.GetHashCode();\n    public override string ToString() =\u003e Value.ToString();\n    public static bool operator ==(ProductId left, ProductId right) =\u003e Equals(left, right);\n    public static bool operator !=(ProductId left, ProductId right) =\u003e !Equals(left, right);\n\n    public bool Equals(ProductId other)\n    {\n        if (ReferenceEquals(null, other)) return false;\n        if (ReferenceEquals(this, other)) return true;\n        return Value == other.Value;\n    }\n\n    public static explicit operator ProductId(int value) =\u003e new ProductId(value);\n    public static explicit operator int(ProductId value) =\u003e value.Value;\n}\n```\n\n`ProductId` is a `ValueObject` class (ie.Wrapper classes).\n\nBelow table shows all supporting Attributes and corresponding Types.\n\n| attribute  | type |\n----|----\n| StringValueObject | string |\n| IntValueObject | int |\n| LongValueObject | long |\n| FloatValueObject | float |\n| DoubleValueObject | double |\n\n## Motivation\n\nNext `Product` class has 2 int type properties, `ProductId` and `ProductCategoryId`.\nSome methods need `ProductId` as an argument, the other methods need `ProductCategoryId` as an argument.\nSometime, developers may mistake between `ProductId` and `ProductCategoryId`.\n\n```csharp\npublic class Product\n{\n    public Product(string name, int productId, int productCategoryId)\n    {\n        Name = name;\n        ProductId = productId;\n        ProductCategoryId = productCategoryId;\n    }\n\n    public string Name { get; }\n    public int ProductId { get; }\n    public int ProductCategoryId { get; }\n}\n```\n\nTo avoid this mistake, we should create `ProductId` class and `CategoryId` class, and use them.\nWith these classes, compiler can detect wrong usage of `ProductId` property and `ProductCategoryId` property.\n\n```csharp\npublic sealed class ProductId: IEquatable\u003cProductId\u003e\n{\n    public int Value { get; }\n\n    public ProductId(int value)\n    {\n        Value = value;\n    }\n\n    public override bool Equals(object obj) =\u003e ReferenceEquals(this, obj) || obj is ProductId other \u0026\u0026 Equals(other);\n    public override int GetHashCode() =\u003e Value.GetHashCode();\n    public override string ToString() =\u003e Value.ToString();\n    public static bool operator ==(ProductId left, ProductId right) =\u003e Equals(left, right);\n    public static bool operator !=(ProductId left, ProductId right) =\u003e !Equals(left, right);\n\n    public bool Equals(ProductId other)\n    {\n        if (ReferenceEquals(null, other)) return false;\n        if (ReferenceEquals(this, other)) return true;\n        return Value == other.Value;\n    }\n\n    public static explicit operator ProductId(int value) =\u003e new ProductId(value);\n    public static explicit operator int(ProductId value) =\u003e value.Value;\n}\n\npublic class CategroyId: IEquatable\u003cCategroyId\u003e\n{\n    public int Value { get; }\n\n    public CategroyId(int value)\n    {\n        Value = value;\n    }\n\n    public override bool Equals(object obj) =\u003e ReferenceEquals(this, obj) || obj is CategroyId other \u0026\u0026 Equals(other);\n    public override int GetHashCode() =\u003e Value.GetHashCode();\n    public override string ToString() =\u003e Value.ToString();\n    public static bool operator ==(CategroyId left, CategroyId right) =\u003e Equals(left, right);\n    public static bool operator !=(CategroyId left, CategroyId right) =\u003e !Equals(left, right);\n\n    public bool Equals(CategroyId other)\n    {\n        if (ReferenceEquals(null, other)) return false;\n        if (ReferenceEquals(this, other)) return true;\n        return Value == other.Value;\n    }\n\n    public static explicit operator CategroyId(int value) =\u003e new CategroyId(value);\n    public static explicit operator int(CategroyId value) =\u003e value.Value;\n}\n\n\npublic class Product\n{\n    public Product(string name, ProductId productId, CategroyId productCategoryId)\n    {\n        Name = name;\n        ProductId = productId;\n        ProductCategoryId = productCategoryId;\n    }\n\n    public string Name { get; }\n    public ProductId ProductId { get; }\n    public CategroyId ProductCategoryId { get; }\n}\n```\n\nThere are many boilerplate code in `ProductId` and `CategoryId` classes.  These boilerplate code is so noisy to read other important meaningful code.\n\n`C# Source Generator` can generate these boilerplate code with smart way. `ValueObjectGenerator` generate ValueObject classes (ie.Wrapper classes) with `C# Source Generator`.\n\nBelow code is example of `ValueObjectGenerator`. There are no boilerplate code to create ValueObjects (ie.Wrapper classes ) like `ProductId` and `CategoryId` classes.\n\n```csharp\n[StringValueObject]\npublic class ProductName { }\n\n[IntValueObject]\npublic class ProductId { }\n\n[IntValueObject]\npublic class CategoryId { }\n\npublic class Product\n{\n    public Product(ProductName name, ProductId productId, CategoryId productCategoryId)\n    {\n        Name = name;\n        ProductId = productId;\n        ProductCategoryId = productCategoryId;\n    }\n\n    public ProductName Name { get; }\n    public ProductId ProductId { get; }\n    public CategoryId ProductCategoryId { get; }\n}\n```\n\n## Plans\n\n* IComparable support.\n* JSON serializer/deserializer.\n* other value types.\n* arithmetic operators support.\n\n## Author\n\nRyota Murohoshi is game Programmer in Japan.\n\n* Posts:http://qiita.com/RyotaMurohoshi (JPN)\n* Twitter:https://twitter.com/RyotaMurohoshi (JPN)\n\n## License\n\nThis library is under MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryotamurohoshi%2Fvalueobjectgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryotamurohoshi%2Fvalueobjectgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryotamurohoshi%2Fvalueobjectgenerator/lists"}