我编写了一段简单的代码来参与 Afterthought,但它不起作用,我不知道为什么。其中很大一部分来自其他 SO 问题:How to implement simple Property Amendment with Afterthought。
using System;
using System.Collections.Generic;
using Afterthought;
namespace SecondAmendmentTest
{
class Program
{
public class TestUser
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool HasChanged { get; set; }
public void method()
{
Console.WriteLine("method");
}
}
public class TestUserAmmendment<T> : Amendment<T, T> where T : TestUser
{
public TestUserAmmendment()
{
Properties
.AfterSet((instance, x, y, z, a) => instance.HasChanged = true);
Methods.After(ExceptionMethod);
}
private object ExceptionMethod(T instance, string method, object[] parameters, object result)
{
throw new NotImplementedException();
}
}
static void Main(string[] args)
{
TestUser tu = new TestUser();
Console.WriteLine("Has changed: " + tu.HasChanged.ToString());
Console.WriteLine("Performing changes...");
tu.Id = 5;
tu.FirstName = "name";
tu.LastName = "lastname";
Console.WriteLine("Has changed: " + tu.HasChanged.ToString());
tu.method();
Console.ReadKey();
}
}
}
它可以编译,但不会对输出的 exe 文件进行任何更改。我已经配置了构建后事件。构建输出:
1>------ Rebuild All started: Project: SecondAmendmentTest, Configuration: Debug Any CPU ------
1> SecondAmendmentTest -> C:\Users\Lukasz\Documents\Visual Studio 11\Projects\SecondAmendmentTest\SecondAmendmentTest\bin\Debug\SecondAmendmentTest.exe
1> Amending SecondAmendmentTest.exe (5,559 seconds)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
最后在运行后从应用程序输出:
C:\Users\Lukasz\Documents\Visual Studio 11\Projects\SecondAmendmentTest\SecondAmendmentTest\bin\Debug>SecondAmendmentTest.exe
Has changed: False
Performing changes...
Has changed: False
method
既未修改 HasChanged 属性,也未引发 NotImplementedException。我正在使用 Git 的最后一个资源。你有什么想法为什么它不起作用?
编辑:这是整个解决方案:SecondAmendmentTest.zip