KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How do I build an Action action in a loop? to explain (sorry it's so lengthy) I have the following: public interface ISomeInterface { void MethodOne(); void MethodTwo(string folder); } public class SomeFinder : ISomeInterface { // elided } and a class which uses the above: public Map Builder.BuildMap(Action<ISomeInterface> action, string usedByISomeInterfaceMethods) { var finder = new SomeFinder(); action(finder); } I can call it with either of these and it works great: var builder = new Builder(); var map = builder.BuildMap(z => z.MethodOne(), "IAnInterfaceName"); var map2 = builder(z => { z.MethodOne(); z.MethodTwo("relativeFolderName"); }, "IAnotherInterfaceName"); How can I build the second implementation programmatically? i.e., List<string> folders = new { "folder1", "folder2", "folder3" }; folders.ForEach(folder => { /* do something here to add current folder to an expression so that at the end I end up with a single object that would look like: builder.BuildMap(z => { z.MethodTwo("folder1"); z.MethodTwo("folder2"); z.MethodTwo("folder3"); }, "IYetAnotherInterfaceName"); */ }); I've been thinking I need an Expression<Action<ISomeInterface>> x or something similar, but for the life of me, I'm not seeing how to construct what I want. Any thoughts would be greatly appreciated!
Tags (comma-separated)
Save Edits
Cancel