CodeBridge.Core
0.0.1
See the version list below for details.
dotnet add package CodeBridge.Core --version 0.0.1
NuGet\Install-Package CodeBridge.Core -Version 0.0.1
<PackageReference Include="CodeBridge.Core" Version="0.0.1" />
<PackageVersion Include="CodeBridge.Core" Version="0.0.1" />
<PackageReference Include="CodeBridge.Core" />
paket add CodeBridge.Core --version 0.0.1
#r "nuget: CodeBridge.Core, 0.0.1"
#:package CodeBridge.Core@0.0.1
#addin nuget:?package=CodeBridge.Core&version=0.0.1
#tool nuget:?package=CodeBridge.Core&version=0.0.1
CodeBridge.Core
Core library for CodeBridge SDK generator. This package contains the core abstractions, services, and models used by CodeBridge to analyze .NET code and generate TypeScript SDKs.
📦 Installation
dotnet add package CodeBridge.Core
🎯 What's Included
Services
SourceAnalyzer - Roslyn-based C# code analyzer
- Discovers endpoints with
[GenerateSdk]attribute - Analyzes types and their properties
- Discovers FluentValidation rules
- Discovers endpoints with
TypeMapper - C# to TypeScript type mapping
- 50+ built-in type mappings
- Generic type support (List<T>, Dictionary<K,V>, etc.)
- Custom type mapping support
- Nullable type handling
CodeGenerator - TypeScript code generation
- Interface generation
- Enum generation
- API client functions
- Validation schemas (Zod)
- React Query hooks
- Next.js server actions
ConfigurationLoader - Configuration management
- JSON-based configuration
- Environment-specific overrides
- Validation and error reporting
Models
- EndpointInfo - API endpoint metadata
- TypeInfo - Type information and properties
- PropertyInfo - Property details
- PropertyValidationRules - Validation rule metadata
- CodeBridgeConfig - Complete configuration model
Attributes
- GenerateSdkAttribute - Mark endpoints for SDK generation
[GenerateSdk( Summary = "Get all products", Group = "products", RequiresAuth = true, Tags = new[] { "products", "catalog" } )]
🔧 Usage
Analyze Source Code
using CodeBridge.Core.Services;
using Microsoft.Extensions.Logging;
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var analyzer = new SourceAnalyzer(loggerFactory.CreateLogger<SourceAnalyzer>());
var projects = new List<ProjectInfo>
{
new() { Name = "MyApi", Path = "/path/to/project" }
};
var endpoints = await analyzer.DiscoverEndpointsAsync(projects, cancellationToken);
var types = await analyzer.DiscoverTypesAsync(projects, cancellationToken);
Map Types
var typeMapper = new TypeMapper(logger, advancedOptions);
var tsType = typeMapper.MapToTypeScript("List<Product>");
// Result: "Product[]"
var tsType2 = typeMapper.MapToTypeScript("Dictionary<string, int>");
// Result: "Record<string, number>"
Generate Code
var generator = new CodeGenerator(logger, typeMapper, targetOptions, featureOptions);
// Generate TypeScript interface
var interfaceCode = await generator.GenerateTypeScriptInterfaceAsync(typeInfo, cancellationToken);
// Generate API function
var functionCode = await generator.GenerateApiClientFunctionAsync(endpoint, cancellationToken);
// Generate React hook
var hookCode = await generator.GenerateReactHookAsync(endpoint, cancellationToken);
Load Configuration
var configLoader = new ConfigurationLoader(logger);
var config = await configLoader.LoadAsync("codebridge.json", cancellationToken);
// Validate configuration
var errors = config.Validate();
if (errors.Count > 0)
{
foreach (var error in errors)
{
Console.WriteLine(error);
}
}
🎨 Type Mappings
Primitives
| C# Type | TypeScript Type |
|---|---|
string |
string |
int, long, decimal, double, float |
number |
bool |
boolean |
DateTime, DateTimeOffset |
string |
Guid |
string |
void |
void |
object, dynamic |
any |
Collections
| C# Type | TypeScript Type |
|---|---|
List<T>, T[], IEnumerable<T> |
T[] |
Dictionary<string, T> |
Record<string, T> |
Dictionary<K, V> |
Map<K, V> |
HashSet<T> |
Set<T> |
Special Types
| C# Type | TypeScript Type |
|---|---|
Result<T> |
Result<T> |
Task<T>, ActionResult<T> |
T (unwrapped) |
Nullable<T>, T? |
T \| null |
IFormFile |
FormData |
Stream |
Blob |
🔌 Extensibility
Custom Type Mappings
{
"advanced": {
"customTypeMappings": {
"MyCustomType": "CustomTsType",
"PagedResult<T>": "PagedResponse<T>"
}
}
}
📚 API Reference
For detailed API documentation, see the API Reference.
🤝 Contributing
This is the core package that powers CodeBridge. Contributions are welcome!
📄 License
MIT License - see LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)
- Microsoft.Extensions.Configuration (>= 9.0.9)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.9)
- Microsoft.Extensions.Configuration.Json (>= 9.0.9)
- Microsoft.Extensions.Logging (>= 9.0.9)
- System.Text.Json (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 182 | 10/10/2025 |
| 1.0.0-preview.8 | 142 | 10/9/2025 |
| 1.0.0-preview.7 | 133 | 10/9/2025 |
| 1.0.0-preview.6 | 142 | 10/9/2025 |
| 1.0.0-preview.5 | 131 | 10/9/2025 |
| 0.0.4 | 189 | 10/9/2025 |
| 0.0.3 | 179 | 10/9/2025 |
| 0.0.2 | 183 | 10/9/2025 |
| 0.0.1 | 192 | 10/2/2025 |