Adding Calor to Existing Projects
This guide walks you through adding Calor to an existing C# project, from enabling Calor to building with mixed Calor/C# code.
Overview
Adding Calor to an existing project is a gradual process:
- Initialize - Enable Calor with MSBuild integration
- Analyze - Find files that benefit most from Calor's features
- Write/Convert - Create new files in Calor, convert high-scoring C# files
- Build - Calor compiles automatically with your project
You don't need to convert everything at once. Calor and C# coexist seamlessly.
Step 1: Enable Calor in Your Project
Enable Calor with MSBuild integration:
Bash
# Initialize Calor in your project
calor init
# Or specify a specific project file
calor init --project MyApp.csprojYour .csproj is updated with MSBuild targets that compile .calr files automatically during dotnet build.
Step 2: Analyze Your Codebase
Use calor analyze to find C# files that would benefit most from Calor:
Bash
# Analyze your source directory
calor analyze ./src
# Show top 10 candidates with detailed scores
calor analyze ./src --top 10 --verboseUnderstanding the Output
Plain Text
=== Calor Migration Analysis ===
Analyzed: 42 files
Average Score: 34.2/100
Top 10 Files for Migration:
--------------------------------------------------------------------------------
82/100 [Critical] src/Services/PaymentProcessor.cs
78/100 [Critical] src/Services/OrderService.cs
65/100 [High] src/Repositories/UserRepository.cs| Priority | Score | Recommendation |
|---|---|---|
| Critical | 76-100 | Convert to Calor - high benefit |
| High | 51-75 | Good conversion candidate |
| Medium | 26-50 | Optional - some benefit |
| Low | 0-25 | Keep in C# - minimal benefit |
Step 3: Add Your First Calor File
Create a new .calr file alongside your existing code:
Plain Text
§M{m001:Calculator}
§F{f001:Add:pub}
§I{i32:a}
§I{i32:b}
§O{i32}
§R (+ a b)
§/F{f001}
§/M{m001}Step 4: Build and Verify
Bash
# Build your project - Calor compiles automatically
dotnet buildThe build process:
- Finds all
.calrfiles in your project - Compiles each to
.g.csin theobj/calor/directory - Includes generated C# in the normal compilation
Step 5: Convert High-Scoring C# Files
Based on your analysis results, convert files that score High or Critical:
Bash
# Convert a single file
calor convert src/Services/PaymentProcessor.cs
# With benchmark comparison
calor convert src/Services/PaymentProcessor.cs --benchmarkFor bulk conversion:
Bash
calor migrate ./src --dry-run # Preview first
calor migrate ./src # ExecuteOptional: Enable Claude Code Integration
For AI-assisted Calor development:
Bash
calor init --ai claudeThis adds:
/calorand/calor-convertskillsCLAUDE.mdwith guidelines instructing Claude to write new code in Calor and analyze C# files before modifying them
Using Claude Code
Write new Calor code:
Plain Text
/calor
Write a function that validates email addresses with:
- Precondition: input is not null or empty
- Postcondition: returns true only for valid emailsConvert existing C# to Calor:
Plain Text
/calor-convert src/Services/PaymentProcessor.csBest Practices
What to Convert First
- High-scoring files from
calor analyze - Files with complex validation - benefit from contracts
- Files with error handling - benefit from
Result\<T,E\> - Files with side effects - benefit from effect declarations
What to Keep in C#
- Simple DTOs and record types
- Auto-generated code (EF migrations, gRPC stubs)
- Code using features Calor doesn't support yet
Next Steps
- Syntax Reference - Complete Calor language reference
- Contracts - Writing preconditions and postconditions
- Effects - Declaring side effects
- calor analyze - Understanding migration scores