bfr/BFR/Operations/ReplaceMode.cs

44 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using System.Collections.Generic;
using BFR.Helpers;
namespace BFR.Operations
{
public class ReplaceOperationMode : OperationMode<ReplaceMode>
{
public bool IsPattern => Index == ReplaceMode.Pattern;
public bool IsCharacters => Index == ReplaceMode.Characters;
public bool IsFromNToN => Index == ReplaceMode.FromNToN;
public bool IsFirstN => Index == ReplaceMode.FirstN;
public bool IsLastN => Index == ReplaceMode.LastN;
public readonly static ReplaceOperationMode[] Modes = All();
protected ReplaceOperationMode(ReplaceMode index, string name, string description) :
base(index, name, description) { }
protected static ReplaceOperationMode[] All() => ((IEnumerable<ReplaceMode>)Enum.GetValues(typeof(ReplaceMode))).Select(x =>
new ReplaceOperationMode(
x,
x.GetAttribute<OperationModeAttribute>().DisplayName,
x.GetAttribute<OperationModeAttribute>().Description
)).ToArray();
}
public enum ReplaceMode
{
[OperationMode(nameof(Pattern), "Replaces the specified pattern.")]
Pattern,
[OperationMode(nameof(Characters), "Replaces each of the specified characters.")]
Characters,
[OperationMode("From N to N", "Replaces everything in the specified range (zero-based indeces).")]
FromNToN,
[OperationMode("First N", "Replaces the first N characters.")]
FirstN,
[OperationMode("Last N", "Replaces the last N characters.")]
LastN,
}
}