Skip to content

Instantly share code, notes, and snippets.

@mzorec
Last active August 2, 2019 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzorec/08b1a651140cfbd18e3d418db2c7d1be to your computer and use it in GitHub Desktop.
Save mzorec/08b1a651140cfbd18e3d418db2c7d1be to your computer and use it in GitHub Desktop.
overriadble options 2
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