Skip to content

Commit 723c72b

Browse files
committed
Add IsValidTypeName function
1 parent 575cf31 commit 723c72b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/WebApiToTypeScript/Types/TypeService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace WebApiToTypeScript.Types
1010
{
1111
public class TypeService : ServiceAware
1212
{
13+
private Regex ValidTypeNameRegex { get; }
14+
= new Regex("^[a-zA-Z_][a-zA-Z0-9_]*$");
15+
1316
private Dictionary<string, List<Type>> PrimitiveTypesMapping { get; }
1417
= new Dictionary<string, List<Type>>();
1518

@@ -37,6 +40,11 @@ public string FixIfReservedWord(string word)
3740
: word;
3841
}
3942

43+
public bool IsValidTypeName(string typeName)
44+
{
45+
return ValidTypeNameRegex.IsMatch(typeName);
46+
}
47+
4048
public void LoadAllTypes(string webApiModuleFilePath)
4149
{
4250
var webApiApplicationModule = ModuleDefinition

0 commit comments

Comments
 (0)