C# to Dart Converter
Convert C# model classes to Dart with json_annotation support.
Features
- Converts C# model classes to Dart following json_annotation package patterns
- Generates clean, modern Dart code with proper null safety
- Handles nested classes and complex type mappings
- Excludes FluentValidation validators automatically
- Smart context menu that appears only when C# code is detected
- Single file output with all related classes
Usage
- Create a new
.dart
file (e.g., models.dart
)
- Paste your C# model code into the file
- Right-click in the editor
- Select "Convert C# to Dart"
- Your C# code is instantly converted to Dart!
Examples
1. Simple Model
Input (C#):
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsAdmin { get; set; }
}
Output (Dart):
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable()
class User {
User({
required this.id,
required this.name,
required this.isAdmin,
});
int id;
String name;
bool isAdmin;
factory User.fromJson(Map<String, dynamic> json) =>
_$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
2. Deeply Nested Model
Input (C#):
public class Company
{
public string CompanyName { get; set; }
public Department[] Departments { get; set; }
public class Department
{
public string DeptName { get; set; }
public Employee[] Employees { get; set; }
public class Employee
{
public int EmpId { get; set; }
public string EmpName { get; set; }
}
}
}
Output (Dart):
import 'package:json_annotation/json_annotation.dart';
part 'company.g.dart';
@JsonSerializable()
class Company {
Company({
required this.companyName,
required this.departments,
});
String companyName;
List<Department> departments;
factory Company.fromJson(Map<String, dynamic> json) =>
_$CompanyFromJson(json);
Map<String, dynamic> toJson() => _$CompanyToJson(this);
}
@JsonSerializable()
class Department {
Department({
required this.deptName,
required this.employees,
});
String deptName;
List<Employee> employees;
factory Department.fromJson(Map<String, dynamic> json) =>
_$DepartmentFromJson(json);
Map<String, dynamic> toJson() => _$DepartmentToJson(this);
}
@JsonSerializable()
class Employee {
Employee({
required this.empId,
required this.empName,
});
int empId;
String empName;
factory Employee.fromJson(Map<String, dynamic> json) =>
_$EmployeeFromJson(json);
Map<String, dynamic> toJson() => _$EmployeeToJson(this);
}