class

Analyzer::CSharp::ServiceStack

Inherits Analyzer::CSharp::Common < Analyzer < FileHelper < Reference < Object

Extracts endpoints from ServiceStack (https://servicestack.net/) request DTOs. Unlike ASP.NET (Core) MVC, the routable unit is the request DTO class itself, not a controller method:

[Route("/hello/{Name}", "GET")] public class Hello : IReturn<HelloResponse> { public string Name { get; set; } }

A DTO class can carry more than one [Route(...)] attribute (one per path/verb combination it answers), and the verb list is a comma (or space) delimited string on the attribute itself — omitted entirely means "every verb". Because each attribute names its own verbs, routes are not cross-multiplied against each other the way FastEndpoints' independent Routes()/Verbs() calls are: /movies and /movies/{Id} in the same class can (and in ServiceStack's own examples do) answer completely different verb sets.

ServiceStack also supports registering the same DTOs from code, inside AppHostBase.Configure():

Routes.Add<Hello>("/hello/{Name}"); Routes.Add<GetContact>("/Contacts", "GET");

which is handled separately: the call site (usually AppHost.cs) rarely lives next to the DTO declaration, so resolving Hello's properties needs a small cross-file type index, similar in spirit to (but simpler than) FastEndpoints' Endpoint<TRequest> resolution.

[Route] is also a legal attribute on Controller actions in classic ASP.NET MVC / Web API, and ASP.NET Core MVC controllers use it too. To avoid stealing those routes (the concern the analyzer project-scoping campaign fixed across the language), this analyzer only looks at files carrying a genuine ServiceStack signal (IReturn/IReturnVoid, using ServiceStack, or the fluent Routes.Add API) and additionally refuses any class whose base list names Controller/ControllerBase — a ServiceStack request DTO never derives from either.

Constants

CLASS_DECL_REGEX = /\b(?:class|record(?:\s+struct)?|struct)\s+(\w+)(?:<[^>]*>)?(?:\s*\([^)]*\))?\s*(?::\s*([^{;]+))?/

class Hello, record Hello(string Name), record struct Hello, struct Hello — an optional generic parameter list, an optional positional-record parameter list, then an optional base list up to the first { (brace body) or ; (positional record with no body).

CONTROLLER_BASE_RE = /\bControllerBase\b|\bController\b/
FLUENT_CALL_RE = /\.Add<(\w+)>\s*\(\s*"([^"]*)"(?:\s*,\s*"([^"]*)")?\s*\)/

Routes.Add<Hello>("/hello/{Name}"), possibly chained (Routes.Add<A>("/a").Add<B>("/b")) or spread across a fluent call chain starting from a bare Routes on its own line.

ROUTE_ATTR_REGEX = /\[\s*Route\s*\(\s*"([^"]*)"(?:\s*,\s*"([^"]*)")?/

[Route("/path")], [Route("/path", "GET")], [Route("/path", "GET,POST")], or with other attributes stacked on the same line ([Route("/x", "POST"),SystemJson(...)]). Deliberately does not match [FallbackRoute(...)] — "Route" must immediately follow [ and optional whitespace.

SERVICESTACK_SOURCE_RE = /\bIReturn(?:Void)?\b|using\s+ServiceStack\b|\bRoutes\.Add\b/

Whole-file gate: only files that show a real ServiceStack fingerprint are scanned at all. \bIReturn\b also matches IReturn<T> (the < is a non-word char, so \b still lands right after "IReturn").

Class methods

tech_name
Source

Instance methods

analyze
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source