changing folder structure
This commit is contained in:
45
Kasbot.APP/Models/Flags.cs
Normal file
45
Kasbot.APP/Models/Flags.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Kasbot.Annotations;
|
||||
|
||||
namespace Kasbot.Models
|
||||
{
|
||||
public class Flags
|
||||
{
|
||||
[Flag("-s", "-silent")]
|
||||
public bool Silent { get; set; }
|
||||
|
||||
[Flag("-r", "-repeat")]
|
||||
public bool Repeat { get; set; }
|
||||
|
||||
public Flags() { }
|
||||
|
||||
public Flags(string command)
|
||||
{
|
||||
this.Parse(command);
|
||||
}
|
||||
|
||||
public string Parse(string command)
|
||||
{
|
||||
string result = command;
|
||||
|
||||
this.GetType().GetProperties().ToList().ForEach(prop =>
|
||||
{
|
||||
Attribute.GetCustomAttributes(prop).ToList().ForEach(attr =>
|
||||
{
|
||||
if (attr is FlagAttribute flag)
|
||||
{
|
||||
flag.Names.ForEach(name =>
|
||||
{
|
||||
if (command.Contains(name))
|
||||
{
|
||||
prop.SetValue(this, true);
|
||||
result = result.Replace(name, string.Empty);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user