30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import re
|
|
|
|
file_path = r"E:\Projects\Finlytic\FinlyticCore\Dtos\Fundamentals\AssetFundamentalsDto.cs"
|
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
lines = f.readlines()
|
|
|
|
out_lines = []
|
|
has_using = any("using System.Text.Json.Serialization;" in l for l in lines)
|
|
if not has_using:
|
|
for i, line in enumerate(lines):
|
|
if "using System;" in line:
|
|
out_lines.append(line)
|
|
out_lines.append("using System.Text.Json.Serialization;\n")
|
|
lines = lines[i+1:]
|
|
break
|
|
|
|
for i, line in enumerate(lines):
|
|
match = re.search(r'^(\s*)public (.+?) ([A-Z][a-zA-Z0-9_]*)( \{.*)$', line)
|
|
if match and " record " not in line and " class " not in line:
|
|
# Check if previous line has JsonPropertyName
|
|
if i == 0 or "JsonPropertyName" not in lines[i-1]:
|
|
indent = match.group(1)
|
|
prop_name = match.group(3)
|
|
camel_name = prop_name[0].lower() + prop_name[1:]
|
|
out_lines.append(f'{indent}[JsonPropertyName("{camel_name}")]\n')
|
|
out_lines.append(line)
|
|
|
|
with open(file_path, "w", encoding="utf-8") as f:
|
|
f.writelines(out_lines)
|