Merged DisplayName and Description attributes into OperationModeAttribute

This commit is contained in:
adroslice 2019-11-21 19:23:25 +01:00
parent ae7c3a3fff
commit ccd9a0efe2
4 changed files with 20 additions and 32 deletions

View File

@ -1,12 +0,0 @@
using System;
namespace BFR.Operations.Attributes
{
class DescriptionAttribute : Attribute
{
public string Description { get; }
public DescriptionAttribute(string description) =>
Description = description;
}
}

View File

@ -1,12 +0,0 @@
using System;
namespace BFR.Operations.Attributes
{
class DisplayNameAttribute : Attribute
{
public string DisplayName { get; }
public DisplayNameAttribute(string displayName) =>
DisplayName = displayName;
}
}

View File

@ -0,0 +1,13 @@
using System;
namespace BFR.Operations
{
class OperationModeAttribute : Attribute
{
public string DisplayName { get; }
public string Description { get; }
public OperationModeAttribute(string displayName, string description) =>
(DisplayName, Description) = (displayName, description);
}
}

View File

@ -3,7 +3,6 @@ using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using BFR.Helpers; using BFR.Helpers;
using BFR.Operations.Attributes;
namespace BFR.Operations namespace BFR.Operations
{ {
@ -23,22 +22,22 @@ namespace BFR.Operations
protected static ReplaceOperationMode[] All() => ((IEnumerable<ReplaceMode>)Enum.GetValues(typeof(ReplaceMode))).Select(x => protected static ReplaceOperationMode[] All() => ((IEnumerable<ReplaceMode>)Enum.GetValues(typeof(ReplaceMode))).Select(x =>
new ReplaceOperationMode( new ReplaceOperationMode(
x, x,
x.GetAttribute<DisplayNameAttribute>().DisplayName, x.GetAttribute<OperationModeAttribute>().DisplayName,
x.GetAttribute<DescriptionAttribute>().Description x.GetAttribute<OperationModeAttribute>().Description
)).ToArray(); )).ToArray();
} }
public enum ReplaceMode public enum ReplaceMode
{ {
[DisplayName(nameof(Pattern)), Description("Replaces the specified pattern.")] [OperationMode(nameof(Pattern), "Replaces the specified pattern.")]
Pattern, Pattern,
[DisplayName(nameof(Characters)), Description("Replaces each of the specified characters.")] [OperationMode(nameof(Characters), "Replaces each of the specified characters.")]
Characters, Characters,
[DisplayName("From N to N"), Description("Replaces everything in the specified range (zero-based indeces).")] [OperationMode("From N to N", "Replaces everything in the specified range (zero-based indeces).")]
FromNToN, FromNToN,
[DisplayName("First N"), Description("Replaces the first N characters.")] [OperationMode("First N", "Replaces the first N characters.")]
FirstN, FirstN,
[DisplayName("Last N"), Description("Replaces the last N characters.")] [OperationMode("Last N", "Replaces the last N characters.")]
LastN, LastN,
} }
} }