Fake DateTime.now C#

0 thích 0 không thích
1 lượt xem
đã hỏi 5 Tháng 7, 2022 trong Lập trình C# bởi nguyenthao (9,000 điểm)
private void Form1_Load(object sender, EventArgs e)
{
    var now = DateTime.Now; // normal now
    var harmony = HarmonyInstance.Create("test");
    // patch
    harmony.PatchAll(Assembly.GetExecutingAssembly());
    
    // now + 100 years
 
    this.Text = DateTime.Now.ToString("dd/MM/yyyy");
}

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show(DateTime.Now.ToString("dd/MM/yyyy"));
}

[HarmonyPatch(typeof(DateTime), "get_Now")]
class Patch
{
    // this method runs after original one
    // __result stores value produced by original
    static DateTime Postfix(DateTime __result)
    {
        // add 100 years to it
        return __result.AddYears(100);
    }
}
Looking for an answer?  Share this question:     

Xin vui lòng đăng nhập hoặc đăng ký để trả lời câu hỏi này.

...