Community Patterns

Community Library Entry

0

Regular Expression
Created·2022-10-11 11:12
Flavor·PCRE2 (PHP)

/
^\s+public (?<type>[\w\[\]]+) (?<prop_1st>\w)(?<prop_rest>[^\W_]+)(?<prop_opt>_(?<opt_1st>\w)(?<opt_rest>[^\W_]+))* { get; set; }$
/
gm
Open regex in editor

Description

When pasting JSON payloads, requests or response as C# classes, the casing of property names is not usually idiomatic C#. This regular expression helps transform the property names while adding System.Text.Json.JsonPropertyName attributes to properties to preserve the original names for serialization.

Submitted by Gareth James