kurnakovv / EnumConverter

EnumConverter is a little open source library for converting enums
MIT License
9 stars 3 forks source link

Converting enums to other enums #9

Closed kurnakovv closed 8 months ago

kurnakovv commented 2 years ago

ToOther

Description

Convert input enums to other enums.

Signature

IEnumerable ToOther<TInputEnum, TOutputEnum>(this IEnumerable, bool [default = true]) where TInputEnum, TOutputEnum : Enum

Type Parameters

TInputEnum - Type of enumValues TOutputEnum - Enum type that we want to get after convert.

Parameters

Returns

IEnumerable<TOutputEnum>

Code examples

// Enums
public enum InputEnum { First, Second, Third }
public enum OutputEnum { First, Second, Third }
IEnumerable<InputEnum> inputEnums = new List<InputEnum>()
{
    InputEnum.First, InputEnum.Second, InputEnum.Third,
};
IEnumerable<OutputEnum> output = inputEnums.ToOther<InputEnum, OutputEnum>(); // or false if case is important.

// output
// 1 - OutputEnum.First
// 2 - OutputEnum.Second
// 3 - OutputEnum.Third