Skip to content

C#

Managed Regex since v1.0

๐Ÿ’Ž Detects public types and members including nullable, async, and array signatures. XML doc-safe.

.cs

What gets detected

The public surface spec-sync tracks for C#.

  • public class / struct / interface / enum / record / delegate
  • public sealed / partial / abstract / static types
  • public methods, properties, fields (including async, virtual, override)

Detection rules

Public type declarations

Matches public followed by any of class, struct, interface, enum, record, delegate. Handles sealed, partial, abstract, and static modifiers.

public class AuthService {}
public struct Config {}
public interface IAuthenticator {}
public enum AuthStatus { Active, Expired }
public record UserProfile(string Name, int Age);
public sealed class Singleton {}
public partial class UserService {}

Public members

Matches public methods, properties, and fields. Handles async, virtual, override, abstract, and new modifiers. Supports nullable and array return types.

public string Validate(string token) {}
public async Task<string> FetchData() {}
public virtual void OnUpdate() {}
public string? FindById(int id) {}
public int[] GetIds() {}

XML doc comment stripping

/// XML doc comments are stripped to prevent false positives from inline documentation examples.

/// <summary>Validates a token</summary>
/// <param name="token">The bearer token</param>
public bool Validate(string token) {}

Example: spec & source

The *.spec.md contract on the left, the C# source it documents on the right. spec-sync matches the two.

Spec (*.spec.md)

---
module: auth
version: 1
status: stable
files:
  - src/Auth/AuthService.cs
---

## Purpose

.NET auth service for the C# platform.

## Public API

| Symbol | Kind | Description |
|--------|------|-------------|
| `AuthService` | class | Main auth class |
| `IAuthenticator` | interface | Auth contract |
| `Validate` | method | Validates a JWT token |
| `AuthStatus` | enum | Active or Expired states |

## Change Log

| Date | Change |
|------|--------|
| 2026-01-01 | Initial |

Source

namespace Example.Auth;

public class AuthService {
    public string Validate(string token) =>
        string.IsNullOrEmpty(token) ? null : token;

    private void InternalCheck() {}
}

public interface IAuthenticator {
    bool Authenticate(string token);
}

public enum AuthStatus { Active, Expired }
public record UserProfile(string Name, int Age);

Test-file patterns

Files matching these are excluded from the detected surface.

Pattern Explanation
**/*Test.cs xUnit / NUnit / MSTest test classes: auto-excluded
**/*Tests.cs Alternate test naming: auto-excluded

Caveats

  • internal, private, and protected members are excluded.
  • Source generators and Roslyn analyzers that emit public code are not detected.
  • Extension methods are captured under their method name.
  • C# 9+ top-level statements are not captured as named symbols.

Related languages