Problems setting List <T> in ListCustomMinIndexedForEach <T> (removed from relevant implementations)

I tried my best to keep the headline short, but still informative.

I think I succeeded with most of this

my problem Now: (TL; DR below)

I was not able to achieve the implementation of a public void element-element or an extension to implement a custom ForEach()with an index.

as extension

    public static ListWithCounter<T> ForEach<T>(this  ListWithCounter<T> Self, Action<T> itm)//, ListWithCounter<T> l = l.CurId)
    {

        for (int i = 0; i < Self.Count; i++)
        {
            Self.CurId = i;
            itm(Self[i]);Self.CurId++;

        }
        return Self;
    }

This is a small problem, I suppose, of the goal :

  • Create an individual list No Unusual additional (expensive) methods

  • add an elegant implementation of ForEach

  • additional tricks, for example, out of the box GetEnumValues/names . To{ourCustomList}()

USING

Enum ( Actions, )

public enum ActSrptS { CreateMmfTfomFile_DoFormat, OpenExitMmfT, .... }

, List

                                    //a struct ConsoleModifiers + ConsoleKey
ActScrptS aAction = ActScrptS._Start; Combination Comb = new Combination();
var actS = aAction._EnmGetValues();
var actSNms = aAction.EnumGetNamesToList().ForEach(Act =>
{
   Console.WriteLine("[{0}]{1}", actS.CurId, Act);
});
Console.WriteLine("===============\r\n");
Console.WriteLine("please Select Action");

(TRYING ..)

public static ListWithCounter<string> EnumGetNamesToList(this Enum selfEnum)
{
    return selfEnum.GetType().GetFields(BindingFlags.Static | BindingFlags.Public)
            .Select(f=>f.Name).ToList();
        //var values = Enum.GetNames(typeof(selfEnum)).ToList();
            //return values;
        //var values = Enum.GetValues(typeof(Environment.SpecialFolder)).Cast<Environment.SpecialFolder>().ToList();

}



public static ListWithCounter<Enum> _EnmGetValues(this Enum Self)
{
    ListWithCounter<Enum> enumerations = new ListWithCounter<Enum>();
    foreach (FieldInfo fieldInfo in Self.GetType().GetFields(
              BindingFlags.Static | BindingFlags.Public))
        {
            enumerations.Add((Enum)fieldInfo.GetValue(Self));
        }
    return enumerations;
}

MSDN List.cs

  • / - , - 10-50, * 4 ...

CODE

+4
1

,

var actS = aActionCur._EnmGetValues().GetAsActionList();


actS.ForEach(act => Console.WriteLine("action [{0}] {1}", actS.CurId, act));
//which is using....v
public static ListWithCounter<Enum> _EnmGetValues(this Enum Self)
{
    ListWithCounter<Enum> enumerations = new ListWithCounter<Enum>();
    foreach (FieldInfo fieldInfo in Self.GetType().GetFields(
              BindingFlags.Static | BindingFlags.Public))
    {
            enumerations.Add((Enum)fieldInfo.GetValue(Self));
    }
        return enumerations;
}


//which is using....v
public static ListWithCounter<T> ForEach<T>(this  ListWithCounter<T> Self, Action<T> itm)
{
        for (int i = 0; i < Self.Count; i++)
        {

            itm(Self[i]); Self.CurId++;
        }
        return Self;
}

    public static ListWithCounter<ConsoleColor> GetAsConColors(this ListWithCounter<Enum> self)
    {
        return self[0].GetType().GetEnumValues().Cast<ConsoleColor>().ToList();
    }

[1]

[2] ... ....

.....

,

0

Source: https://habr.com/ru/post/1629780/


All Articles