from pathlib import Path s = Path('Client/Assets/Scripts/Core/PlayFabMgr.cs').read_text(encoding='utf-8-sig') def block(marker): start = s.index(marker) a = s.index('{', start) n, end = 1, a + 1 while n: n += (s[end] == '{') - (s[end] == '}') end += 1 return s[start:end] code = '''using System;using System.Collections.Generic;using System.Threading; public class Subject { public LinkedList> dataBuffer = new(); public Dictionary swapData = new(); public CancellationTokenSource tokenSource = new(); public void Flush()=>SyncData(); public void Destroy()=>OnDestroy(); public void UpdateFaild(object error){} ''' code += block('void OnDestroy()') + '\n' + block('private void SyncData()') + '\n}\n' Path('CodexOutput/upserver/LogoutStorageTests/Generated.cs').write_text(code, encoding='utf-8')