question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add parameter overload for CakeTaskBuilder.Does.

See original GitHub issue

I would to use a pattern like the following to dynamically build tasks. The problem is that by running .\build.ps1 -target DefaultB I get an null reference for folder in the does delegate. This is possible through closure, isn’t it?

var folders = new []{"A","B"};
var target = Argument("target","DefaultA");

foreach(var folder in folders)
{
  Task("Default"+folder)
    .Does(folder =>
    {
      CreateDirectory(folder);
      //something else
    });
}

RunTarget(target);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RichiCoder1commented, Nov 22, 2016

I believe the correct way is this:

var folders = new []{"A","B"};
var target = Argument("target","DefaultA");

foreach(var folder in folders)
{
  var localFolder = folder;
  Task("Default"+folder)
    .Does(()=>
    {
      CreateDirectory(localFolder);
      //something else
    });
};
0reactions
devleadcommented, Sep 28, 2017

This is addressed by #1767

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflicting overloaded methods with optional parameters
An overload which doesn't require any optional parameters to be filled in automatically is preferred to one which does.
Read more >
Member Overloading - Framework Design Guidelines
In this article. Member overloading means creating two or more members on the same type that differ only in the number or type...
Read more >
Overloading
Overloading causes a lot less of a problem when only one method will ever be applicable - for example when the parameter types...
Read more >
Overload resolution
In practice, the rules for determining overload resolution are intended to find the overload that is "closest" to the actual arguments ...
Read more >
When should method overloads be refactored?
I believe the common approach is to encapsulate some (or all) of the parameters into a class and have that as a parameter:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found