mardi 19 mai 2020

Loop through List

I used Reflection to get all relevant information out of a Class Libary (.dll). It returns a List of Object-Arrays, which I created

list.Add(new object[] { args.Select(x => x.Value) });

Each Object-Array contains a System.Reflection.CustomAttributeTypedArgument, object. My goal is to get all values of each Object[].

foreach (var type in types)
{

    MethodInfo[] declaredMethods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public);

    foreach (var method in declaredMethods)
    {
        foreach (var test in method.CustomAttributes)
        {
            var args = test.ConstructorArguments;
            foreach (var arg in args)
            {
                if (args.Count > 0 && 
                    arg.ToString().Contains(Path.GetFileName(path)))
                {
                    list.Add(new object[] { args.Select(x => x.Value) });     
                }
            }
        }
    }
}

I get some arrays with the information I want to work with. But I cant reach it while iterating.





Aucun commentaire:

Enregistrer un commentaire