C# to Protobuf Converter - Generate a Protocol Buffer Schema from C# Classes
Turn C# classes, records, structs and enums into a proto3 .proto schema with nested messages, repeated and map fields.
How to Convert C# to Protobuf - Step by Step Guide
Input Your C# Class Definitions
Start by entering your C# class definitions that need to be converted to Protocol Buffer schema:
Example: C# Class Input
Here's a typical C# POCO ready for protobuf conversion:
namespace Example { public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } public List<string> Roles { get; set; } public bool Active { get; set; } public UserProfile Profile { get; set; } } public class UserProfile { public string Department { get; set; } public int ExperienceYears { get; set; } public List<string> Skills { get; set; } } }
Automatic Schema Generation
The tool automatically analyzes your C# classes and generates a corresponding Protocol Buffer schema:
Example: Generated Protobuf Schema
The same C# classes, now converted to protobuf schema:
syntax = "proto3"; package example; option csharp_namespace = "Example"; message User { int32 id = 1; string name = 2; string email = 3; repeated string roles = 4; bool active = 5; UserProfile profile = 6; } message UserProfile { string department = 1; int32 experience_years = 2; repeated string skills = 3; }
Copy or Download Protobuf Schema
When the schema looks right, take it with you:
Example: Generated Protobuf Schema
The same C# classes, now converted to protobuf schema:
syntax = "proto3"; package example; option csharp_namespace = "Example"; message User { int32 id = 1; string name = 2; string email = 3; repeated string roles = 4; bool active = 5; UserProfile profile = 6; } message UserProfile { string department = 1; int32 experience_years = 2; repeated string skills = 3; }
Frequently Asked Questions
Why generate a .proto file from C# classes?
Moving a .NET service to gRPC usually starts with DTOs or POCOs that already exist. Writing the matching messages by hand means retyping every property and picking a field number for each one. Starting from the classes gives you a first schema in seconds, and you then adjust the few places where proto3 works differently from C#.
How are C# types mapped?
int, short and sbyte become int32; byte, ushort and uint become uint32; long becomes int64 and ulong becomes uint64, so an ID like 8901240544102066246 still fits. float, double and bool map straight across, string, char and Guid become string, and byte[] becomes bytes. List<T>, arrays, HashSet<T> and the other collections become repeated fields, Dictionary<K, V> becomes map<K, V>, and a nullable value type such as int? becomes an optional field. decimal, DateTime, DateTimeOffset and TimeSpan have no exact proto scalar, so they are written as string with a comment that names the typed alternative.
Which members end up in the message?
Public auto-properties (get; set; or get; init;), public fields and the parameters of positional records. Static and const members, private members, computed properties such as Total => Price * Qty, methods, constructors, events and indexers are left out, and so is anything marked [JsonIgnore]. A private member marked [JsonInclude], [JsonProperty] or [DataMember] is kept, because the serializer would write it too.
What happens to nested classes, enums, records and inheritance?
Nested classes become nested messages and enums become proto enums. Each enum gets an _UNSPECIFIED = 0 value first, as proto3 requires, and the enum name as a prefix so two enums never clash. That means the numbers start again from 1: if your C# enum sets its own values or uses [Flags], a comment above it says those values were not kept. Partial classes are merged into one message, and when a class derives from another class in the input, the base class properties are copied in first, since protobuf has no inheritance.
How are property names and field numbers chosen?
PascalCase names become snake_case, so ExperienceYears turns into experience_years and UserID into user_id. If two properties end up with the same name (Id and ID, for example), the second one gets a _2 suffix. Numbers run from 1 in the order the members appear. A name set with [JsonPropertyName], [JsonProperty] or [DataMember(Name = ...)] is kept as json_name, so JSON output still uses it. When the file has a namespace, it becomes the package and also goes into option csharp_namespace.
What if a property has no proto equivalent?
Lists of lists, multi-dimensional arrays, dictionaries with enum or object keys, tuples, object and dynamic, generic type parameters and classes that are not in your input are written as string fields with a comment explaining why, often with a hint to wrap the inner part in its own message. Every schema is run through a .proto parser before it is shown, and broken C#, such as a brace that is never closed, gets an error with the line number instead of a half-finished schema.
Is my code uploaded anywhere?
No. The conversion runs in your browser and nothing is sent to a server or kept after you leave the page. It only reads the type declarations, so your code is never compiled or run.