Loading Gist 7517928
I want to refactor this to generalize. I'm not going to add additional tests just yet, even though maybe I should. At least I have enough test coverage that I don't have to spend time manually testing as I go.
I used very small steps, but the outline is:
- Extract Method LogInputs, push it up to base class LoggingTask
- Replace the hard-coded "Foo" and this.Foo with reflection via this.GetType().GetProperty("Foo").Name and .GetValue(this).
- Extract method LogInput, taking a PropertyInfo
- Replace GetProperty() with a loop over GetProperties(), filtering by the [Required] attribute.
- Extract Method GetPropertyInfos and HasAttribute.
Here's the result:
As an indication that I'm on the right track, see how small the test task is:
Loading Gist 7521995
You will also need this extension:
Loading Gist 7522018
I don't really like that he [Required] attribute is used to find parameters; that's not quite the right rule. But I'll come back to that later.
No comments:
Post a Comment