I’m trying to figure out Afterthought. I want to set the variable HasChanged when any property setter is called. I have the following code
public class TestUser
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool HasChanged { get; set; }
}
public class TestUserAmmendment<T> : Amendment<T, T> where T : TestUser
{
public TestUserAmmendment()
{
Properties
.Where(p => p.PropertyInfo.CanRead
&& p.PropertyInfo.CanWrite
&& p.PropertyInfo.GetSetMethod().IsPublic
&& p.Name != "HasChanged")
.AfterSet(instance.HasChanged = true);
}
}
but I am receiving a compiler error saying The name 'Properties' does not exist in the current context. I have copied the code from the unit tests, which I can compile and run. I’m not sure, but does anyone know how I can implement this simple aspect using Afterthought?
Your sample code compiles for me.
The fluent interface was not added, I believe, until version 1.0.8, which is the most current version. Try updating to the latest version, and if you are still having problems, I’ll see if I can help further.
Edit
I actually did have to make one change to get it to compile the first time I tried. I changed the
AfterSetto:But since that wasn’t really part of the question, I promptly forgot about it. 🙂