Closed InteXX closed 5 years ago
Can you use myFolder.Tasks["TaskName"]
?
Hm, I guess I missed that one.
OK, never mind :-)
Oops, it throws an exception if the task doesn't exist.
Here's my extension method:
Friend Module Extensions
<Extension>
Public Function GetTask(Folder As TaskFolder, Name As String) As Task
Return TaskService.Instance.GetTask($"{Folder.Name}\{Name}")
End Function
End Module
If you want to make it folder-centric, you could also do
Return Folder.GetTasks(Name).FirstOrDefault()
Yes, I did consider the FirstOrDefault
/ SingleOrDefault
approach, but I didn't want to drag out RegEx
for that. (RegEx
is far from comfortable for me, I must admit.)
Perhaps an overload accepting a String
for the task name would accomplish the same thing.
Given that there are multiple ways to accomplish this same task, I'm reticent to add yet another. Of the two approaches above, the second (which I proposed) is likely faster. Using a full string with RegEx effectively just does a string compare. By querying from the folder, you reduce the number of tasks that have to be searched.
OK, no problem.
Is your feature request related to a problem? Please describe. It's not related to a problem. It's a request for a convenience feature.
Describe the solution you'd like Could you add a
GetTask(Name As String)
method to theTaskFolder
class. While it's true that we currently have this as a method on theTaskService
class, that method requires the full path to the task.TaskFolder.GetTask(Name As String)
could be used in cases where we don't necessarily have the full path but we do have aTaskFolder
object.Describe alternatives you've considered If this isn't feasible, we can always use an extension method.
Additional context None.