Last active
August 2, 2019 09:04
-
-
Save mzorec/08b1a651140cfbd18e3d418db2c7d1be to your computer and use it in GitHub Desktop.
overriadble options 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using FlubuCore.Tasks.Process; | |
namespace FlubuCore.Tests.Tasks | |
{ | |
public class ExampleTask2 : ExternalProcessTaskBase<int, ExampleTask> | |
{ | |
protected override string Description { get; set; } | |
[ArgKey("-c", "--configuration")] | |
public ExampleTask2 Configuration(string value) | |
{ | |
WithArgumentsKeyFromAttribute(value); | |
return this; | |
} | |
[ArgKey("-r", "--runtime")] | |
public ExampleTask2 Runtime(string value) | |
{ | |
WithArgumentsKeyFromAttribute(value); | |
return this; | |
} | |
private void WithArgumentsKeyFromAttribute(string value, [CallerMemberName] string memberName = "") | |
{ | |
var method = GetType().GetRuntimeMethods().FirstOrDefault(x => x.Name == memberName); | |
if (method == null) return; | |
var attribute = method.GetCustomAttribute<ArgKey>(); | |
WithArguments(attribute.Keys[0], value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment