{"id":33322587,"url":"https://github.com/pekspro/DataAnnotationValuesExtractor","last_synced_at":"2025-11-24T23:00:44.509Z","repository":{"id":324582965,"uuid":"1079191277","full_name":"pekspro/DataAnnotationValuesExtractor","owner":"pekspro","description":"A C# source generator that automatically extracts values from data annotation attributes and exposes them as strongly-typed constants.","archived":false,"fork":false,"pushed_at":"2025-11-16T19:03:02.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-16T19:22:59.325Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pekspro.png","metadata":{"files":{"readme":"README-NuGet.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-19T09:59:56.000Z","updated_at":"2025-11-16T18:54:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pekspro/DataAnnotationValuesExtractor","commit_stats":null,"previous_names":["pekspro/dataannotationvaluesextractor"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pekspro/DataAnnotationValuesExtractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pekspro%2FDataAnnotationValuesExtractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pekspro%2FDataAnnotationValuesExtractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pekspro%2FDataAnnotationValuesExtractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pekspro%2FDataAnnotationValuesExtractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pekspro","download_url":"https://codeload.github.com/pekspro/DataAnnotationValuesExtractor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pekspro%2FDataAnnotationValuesExtractor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284767943,"owners_count":27060132,"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-11-16T02:00:05.974Z","response_time":65,"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":[],"created_at":"2025-11-20T04:00:37.037Z","updated_at":"2025-11-24T23:00:44.494Z","avatar_url":"https://github.com/pekspro.png","language":"C#","readme":"# DataAnnotationValuesExtractor\n\nA C# source generator that automatically extracts values from data annotation\nattributes and exposes them as strongly-typed constants. Access your\n`StringLength`, `Range`, `Required` and `Display` attribute values as constants\nin your classes.\n\n## Why Use This?\n\nWhen working with data annotations, you often need to reference validation\nconstraints. A good way to solve it is to create constants. But it takes time to\ndo and makes your data models harder to read. And it's harder when your models\nare auto generated like when you are scaffolding with Entity Framework.\n\nThis source generator creates the constants automatically for you. If you have\nthis model:\n\n```csharp\npublic partial class Product\n{\n    [Required]\n    [StringLength(100)]\n    public string? Name { get; set; }\n\n    [Required]\n    [Range(0.01, 999999.99)]\n    public decimal Price { get; set; }\n}\n```\n\nConstants will be generated that you can access like this:\n\n```csharp\n// Name length constraints\nint maxNameLength = Product.Annotations.Name.MaximumLength; // 100\nbool nameRequired = Product.Annotations.Name.IsRequired; // true\n\n// Price constraints\ndouble minPrice = Product.Annotations.Price.Minimum; // 0.01\ndouble maxPrice = Product.Annotations.Price.Maximum; // 999999.99\n```\n\n## Usage Patterns\n\nThere are two ways to configure DataAnnotationValuesExtractor depending on your\nneeds:\n\n### 1. Direct Approach\n\nApply `[DataAnnotationValues]` directly to each class you want to generate\nconstants for:\n\n```csharp\n[DataAnnotationValues(StringLength = true, Range = true, Required = true, Display = true)]\npublic partial class Product\n{\n    [Display(Name = \"Product name\")]\n    [Required]\n    [StringLength(100)]\n    public string? Name { get; set; }\n\n    [Display(Name = \"Product price\")]\n    [Required]\n    [Range(0.01, 999999.99)]\n    public decimal Price { get; set; }\n\n    public string? Sku { get; set; }\n}\n```\n\n### 2. Centralized Approach\n\nCreate a dummy class and use the `DataAnnotationValuesToGenerate` attribute for\neach class you want to generate constants for. You can use the\n`DataAnnotationValuesConfiguration` attribute to configure what to be generated.\n\n```csharp\nusing Pekspro.DataAnnotationValuesExtractor;\n\n[DataAnnotationValuesConfiguration(StringLength = true, Range = true, Required = true, Display = true)]\n[DataAnnotationValuesToGenerate(typeof(Customer))]\n[DataAnnotationValuesToGenerate(typeof(Order))]\n[DataAnnotationValuesToGenerate(typeof(Product))]\npartial class ValidationConstants\n{\n}\n```\n\nYour model classes remain unchanged.\n\nThis approach is especially useful when working with auto-generated models, such\nas those created by Entity Framework scaffolding.\n\n### Use the generated constants\n\nNo matter which approach your are using, you can access generated constants like\nthis:\n\n```csharp\n// Name\nint maxNameLength = Product.Annotations.Name.MaximumLength; // 100\nint minNameLength = Product.Annotations.Name.MinimumLength; // 0\nbool nameRequired = Product.Annotations.Name.IsRequired; // true\nstring? nameDisplayName = Product.Annotations.Name.Display.Name; // Product name\n\n// Price\ndouble minPrice = Product.Annotations.Price.Minimum; // 0.01\ndouble maxPrice = Product.Annotations.Price.Maximum; // 999999.99\nbool priceRequired = Product.Annotations.Price.IsRequired;\nstring? priceDisplayName = Product.Annotations.Price.Display.Name; // Price name\n\n// Sku\nbool skuRequired = Product.Annotations.Sku.IsRequired; // false\n```\n\n## Installation\n\nAdd the package to your project:\n\n```bash\ndotnet add package Pekspro.DataAnnotationValuesExtractor\n```\n\nFor optimal setup, configure the package reference in your `.csproj` to exclude\nit from your output assembly:\n\n```xml\n\u003cItemGroup\u003e\n  \u003cPackageReference Include=\"Pekspro.DataAnnotationValuesExtractor\" Version=\"0.0.1\" \n    PrivateAssets=\"all\" ExcludeAssets=\"runtime\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n## Links\n\nYou can find more information and can report issues on [GitHub](https://github.com/pekspro/DataAnnotationValuesExtractor).\n","funding_links":[],"categories":["Source Generators"],"sub_categories":["Other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpekspro%2FDataAnnotationValuesExtractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpekspro%2FDataAnnotationValuesExtractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpekspro%2FDataAnnotationValuesExtractor/lists"}