Chd.AutoUI
1.0.0
See the version list below for details.
dotnet add package Chd.AutoUI --version 1.0.0
NuGet\Install-Package Chd.AutoUI -Version 1.0.0
<PackageReference Include="Chd.AutoUI" Version="1.0.0" />
<PackageVersion Include="Chd.AutoUI" Version="1.0.0" />
<PackageReference Include="Chd.AutoUI" />
paket add Chd.AutoUI --version 1.0.0
#r "nuget: Chd.AutoUI, 1.0.0"
#:package Chd.AutoUI@1.0.0
#addin nuget:?package=Chd.AutoUI&version=1.0.0
#tool nuget:?package=Chd.AutoUI&version=1.0.0
Chd.AutoUI
Metadata-Driven UI Generation Framework
Chd.AutoUI is a framework that automatically generates CRUD interfaces using C# attributes. Simply add attributes to your DTO classes to generate all the necessary metadata for frontend consumption in JSON format.
๐ฏ Features
- C# Centric: Create UI metadata by writing only C# code
- Attribute-Based: Define UI with
[AutoCRUD],[GridColumn],[FormField]attributes - Framework Agnostic: Works with any frontend framework like React, Vue, Angular
- Type-Safe: Reflection-based metadata generation
- Extensible: Add your own attributes and field types
๐ฆ Installation
dotnet add package Chd.AutoUI
๐ Quick Start
1. Create Your DTO Class
using Chd.AutoUI.Attributes;
[AutoCRUD(Title = "Products", Icon = "๐ฆ", Route = "/products", Description = "Product management")]
public class ProductDto
{
[GridColumn(Order = 1, Width = 80)]
[FormField(ReadOnly = true)]
public int Id { get; set; }
[GridColumn(Order = 2, Width = 200)]
[FormField(Label = "Product Name", Type = FieldType.Text, Required = true, MaxLength = 250, Order = 1)]
public string Name { get; set; } = string.Empty;
[GridColumn(Order = 3, Width = 150, Format = "currency")]
[FormField(Label = "Price", Type = FieldType.Number, Required = true, Order = 2)]
public decimal Price { get; set; }
[GridColumn(Order = 4, Width = 100)]
[FormField(Label = "Active", Type = FieldType.Checkbox, Order = 3)]
public bool IsActive { get; set; }
}
2. Generate Metadata
using Chd.AutoUI.Services;
var generator = new MetadataGenerator();
var metadata = generator.GenerateMetadata<ProductDto>();
// metadata can be serialized as JSON
var json = JsonSerializer.Serialize(metadata);
3. Create API Endpoint
[ApiController]
[Route("api/[controller]")]
public class MetadataController : ControllerBase
{
private readonly MetadataGenerator _generator;
public MetadataController()
{
_generator = new MetadataGenerator();
}
[HttpGet]
public IActionResult GetAllEntities()
{
var assembly = typeof(ProductDto).Assembly;
var entities = _generator.ScanAssemblyForEntities(assembly);
return Ok(entities);
}
[HttpGet("{entityName}")]
public IActionResult GetEntityMetadata(string entityName)
{
var assembly = typeof(ProductDto).Assembly;
var type = assembly.GetTypes()
.FirstOrDefault(t => t.Name.Equals(entityName, StringComparison.OrdinalIgnoreCase));
if (type == null)
return NotFound($"Entity '{entityName}' not found");
var metadata = _generator.GenerateMetadata(type);
return Ok(metadata);
}
}
๐ Attributes
AutoCRUDAttribute
Defines general UI settings for the entity.
[AutoCRUD(
Title = "Products", // Title displayed in UI
Icon = "๐ฆ", // Icon (emoji or icon class)
Route = "/products", // Frontend route
Description = "Product list" // Description
)]
public class ProductDto { }
GridColumnAttribute
Defines grid/table columns.
[GridColumn(
Order = 1, // Sort order
Width = 150, // Width in pixels
Sortable = true, // Is sortable?
Format = "currency", // Format type: "currency", "date", "percent", "number"
Hidden = false // Is hidden?
)]
public decimal Price { get; set; }
Format Types:
currency: Currency format (e.g., $1,234.56)date: Date format (e.g., 01/15/2024)percent: Percentage format (e.g., 75%)number: Number format (e.g., 1,234.56)
FormFieldAttribute
Defines form fields.
[FormField(
Label = "Product Name", // Form label
Type = FieldType.Text, // Field type
Required = true, // Is required?
MaxLength = 250, // Maximum length
Placeholder = "Enter name", // Placeholder text
Order = 1, // Form order
ReadOnly = false // Is read-only?
)]
public string Name { get; set; }
Field Types:
Text: Text inputNumber: Number inputEmail: Email inputPassword: Password inputTextarea: Multi-line textDate: Date pickerCheckbox: CheckboxSelect: Dropdown listFile: File upload
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C# DTO Classes โ
โ [AutoCRUD] [GridColumn] [FormField] โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MetadataGenerator (Reflection) โ
โ - ScanAssemblyForEntities() โ
โ - GenerateMetadata<T>() โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ JSON Metadata (REST API) โ
โ GET /api/metadata โ
โ GET /api/metadata/{entityName} โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend (React/Vue/Angular) โ
โ - DynamicGrid Component โ
โ - DynamicForm Component โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ JSON Metadata Format
{
"entityName": "ProductDto",
"title": "Products",
"icon": "๐ฆ",
"route": "/products",
"description": "Product management",
"grid": {
"columns": [
{
"propertyName": "Id",
"title": "Id",
"type": "number",
"order": 1,
"width": 80,
"sortable": true,
"format": null,
"hidden": false
},
{
"propertyName": "Name",
"title": "Name",
"type": "string",
"order": 2,
"width": 200,
"sortable": true,
"format": null,
"hidden": false
}
]
},
"form": {
"fields": [
{
"propertyName": "Name",
"label": "Product Name",
"type": "text",
"required": true,
"maxLength": 250,
"placeholder": "Enter name",
"order": 1,
"readOnly": false
}
]
}
}
๐ง Advanced Usage
Assembly Scanning
To automatically discover all DTOs:
var generator = new MetadataGenerator();
var assembly = typeof(ProductDto).Assembly;
var allEntities = generator.ScanAssemblyForEntities(assembly);
// allEntities: metadata for all classes with [AutoCRUD] attribute
Adding Custom Field Types
You can extend the FieldType enum to add your own field types:
public enum CustomFieldType
{
// Standard types
Text = 0,
Number = 1,
// ...
// Custom types
RichTextEditor = 100,
ColorPicker = 101,
ImageUploader = 102
}
๐งช Test Examples
Simple Entity
[AutoCRUD(Title = "Categories", Icon = "๐", Route = "/categories")]
public class CategoryDto
{
[GridColumn(Order = 1, Width = 80)]
[FormField(ReadOnly = true)]
public int Id { get; set; }
[GridColumn(Order = 2, Width = 200)]
[FormField(Label = "Category Name", Type = FieldType.Text, Required = true, MaxLength = 100, Order = 1)]
public string Name { get; set; } = string.Empty;
}
Related Entity
[AutoCRUD(Title = "Products", Icon = "๐ฆ", Route = "/products")]
public class ProductDto
{
[GridColumn(Order = 1, Width = 80)]
[FormField(ReadOnly = true)]
public int Id { get; set; }
[GridColumn(Order = 2, Width = 200)]
[FormField(Label = "Product Name", Type = FieldType.Text, Required = true, Order = 1)]
public string Name { get; set; } = string.Empty;
[GridColumn(Order = 3, Width = 150)]
[FormField(Label = "Category", Type = FieldType.Select, Required = true, Order = 2)]
public int CategoryId { get; set; }
[GridColumn(Order = 4, Width = 150)]
public string? CategoryName { get; set; }
}
๐ ๏ธ Technologies
- .NET 8.0
- System.Reflection - For metadata generation
- Microsoft.EntityFrameworkCore - For entity support
๐ Frontend Integration
React Components (npm)
For automatic UI generation in React, use our companion npm package:
npm install @mehmetyoldas/chd-auto-ui-react
Complete Integration Example:
// 1. Backend: C# DTO with attributes
[AutoCRUD(Title = "Products", Icon = "๐ฆ")]
public class ProductDto
{
[GridColumn(Order = 1)] [FormField(Type = FieldType.Text)]
public int Id { get; set; }
[GridColumn(Order = 2)] [FormField(Type = FieldType.Text, Required = true)]
public string Name { get; set; }
}
// 2. API Controller
[HttpGet("metadata")]
public IActionResult GetMetadata() => Ok(MetadataGenerator.GenerateMetadata<ProductDto>());
// 3. Frontend: React components
import { DynamicForm, DynamicGrid } from '@mehmetyoldas/chd-auto-ui-react';
function ProductManager() {
return (
<div>
<DynamicForm
apiUrl="/api/products"
metadataUrl="/api/products/metadata"
/>
<DynamicGrid
apiUrl="/api/products"
metadataUrl="/api/products/metadata"
/>
</div>
);
}
๐ React Package Documentation: npm package
๐ License
MIT License
๐ค Contributing
- Fork the project
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Contact
Chd Framework - metadata-driven UI generation
๐ Related Projects
- Chd.AutoUI.EF - Generic Repository Pattern
- Chd.Pos - POS Demo Application
- Chd.StockTracking - Stock Tracking Demo Application
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.