A C# file is unusually honest about where it comes from. The namespace carries the company, the DbContext carries the schema, the interpolated log lines carry the product’s own words.

What a .NET snippet carries

Look at an ordinary controller through a stranger’s eyes. namespace Acme.Billing.Api.Controllers introduces the company and the system. BillingDbContext and a LINQ chain over Invoices.Where(i => !i.IsPaid) reconstruct the data model. The route template, the NotFound message and the structured log line write out the business process in plain English. The comment above the class helpfully adds the ticket number.

Anonymized, the same file is a controller in Pkg1.Pkg2 querying a Class1 for Prop2 under some cutoff. Everything a reviewer needs, nothing a competitor wants.

How the pass works

Your namespaces, classes, records, methods, properties, fields, locals and parameters become placeholders in .NET casing: Pkg1, Class2, Method3, Prop4, var5, param6, CONST_7. What arrives through using lines from System, Microsoft and a wide list of NuGet ecosystems, EF Core, Serilog, MediatR, xUnit, Moq and so on, stays readable, as do dictated method names like ToString, Dispose or OnModelCreating. Attributes follow the same origin rule, [HttpGet] survives while your own [AuditedAttribute] does not.

Comments are removed by default. String literals are masked by default. Numbers stay, with five-plus-digit ones flagged for a manual look. The layout is preserved down to the whitespace, the result diffs cleanly against the original.

Everything runs in the tab. The page ships the engine as a script, there is no upload and no server-side processing to trust.

Interpolated, verbatim, raw

C# has four string syntaxes and they leak differently. The tool lexes them the way the compiler does. In an interpolated $"..." the literal pieces are masked while the expressions in the braces stay code and get renamed with everything else, alignment and format specs included as syntax. Verbatim @"..." and raw """...""" strings are masked as a whole, with a raw string keeping its line structure. Char literals stay.

Structured logging templates deserve a sentence of their own. _logger.LogInformation("Customer {CustomerId} owes {Total}", ...) holds its placeholders inside an ordinary string, and after masking, the named holes are gone along with the wording. That is the safe default for sharing. Restore brings the original template back.

An obfuscator solves a different problem

Searching for hiding C# code mostly surfaces assembly obfuscators, which protect software you ship from the people who receive it. Sharing a snippet for review inverts every requirement. The recipient is the one party who must read the code fluently, and you are the one party who must be able to undo the renaming. So the placeholder names stay conventional, the framework surface stays visible, and reversibility is the core feature rather than an attack.

If both needs apply, they compose in sequence, anonymize what you share during development, obfuscate what you compile for customers.

Getting the names back

The key maps each placeholder to its original with role and usage count, lives in your browser’s localStorage, and exports as a JSON file for a colleague or another machine. Restore mode applies it to whatever you paste, the model’s full rewritten file included. Placeholders it never issued are listed rather than guessed, matching is case-exact, and a placeholder inside a longer name the reviewer coined, say Class1Factory, is deliberately left as their naming.

The intended loop, in one line: anonymize, let the model rewrite Method3, restore, and diff the suggestion against your original in the IDE.

Before the code leaves the solution

Do AI coding assistants store the code you paste?

Assume yes until the product documentation for your specific plan says otherwise. Retention, human review and training use differ between consumer and business tiers of the same product and change over time, which is why the durable strategy is to control what goes in rather than what happens to it afterwards. Code that arrives as Class1 and Method2 is a much smaller bet on someone else’s data handling.

How do I anonymize C# code before asking for help online?

Strip the three carriers of context, your identifiers, your string literals and your comments, while keeping the .NET and library surface readable, and keep a mapping for the way back. Paste the file above and that is the whole procedure, done locally in the browser.

What does an interpolated string leak?

The literal text between the holes, which is typically log wording, error prose or route fragments written in your product’s vocabulary. The expressions in the braces are code and leak names instead. Both halves need handling, which is why they are processed separately here.

Are connection strings in code sensitive?

Yes. One names your server, database and account, sometimes the password too. Masked it collapses to str_1. Rotate anything already pasted somewhere.

Is Dotfuscator the right tool for sharing code snippets?

No. Dotfuscator, ConfuserEx and similar tools harden compiled assemblies against decompilation, and readability is exactly what they destroy. For a snippet that a person or a model should reason about you want the reverse, readable code minus your vocabulary, plus a way to undo the renaming. That is an anonymizer, not an obfuscator.

Can I share an EF Core query without exposing the schema?

Yes. DbSet names and entity properties are your schema and get placeholders, while Where, Sum and AsNoTracking stay, so the query stays diagnosable as LINQ. The answer usually hinges on the operators anyway, not on what the table is called.

What is safe to leave in a shared snippet?

Framework types, NuGet APIs, HTTP verbs and format strings. They are identical in every codebase and carry what an answer needs.