This is an old revision of the document!
using System; using System.IO; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string filePath = "YourFilePath.cs"; // 替換為你的檔案路徑 string className = "Json1"; string newCode = @" public uint gData1 { get; set; } // [1] gData1 public Int16 gData2 { get; set; } // [2] gData2 public Int16 gData3 { get; set; } // [4] gData3 public Int16 gData4 { get; set; } // [5] gData4 public Int32 gData5 { get; set; } // [6] gData5 "; ReplaceClassCode(filePath, className, newCode); } static void ReplaceClassCode(string filePath, string className, string newCode) { // 讀取檔案內容 string fileContent = File.ReadAllText(filePath); // 使用正則表達式尋找 class 並替換其內容 string pattern = $@"(public class {className}\s*{{\s*).*?(}})"; string replacement = $"$1{newCode}$2"; string updatedContent = Regex.Replace(fileContent, pattern, replacement, RegexOptions.Singleline); // 寫回檔案 File.WriteAllText(filePath, updatedContent); Console.WriteLine($"Class {className} has been updated successfully."); } }