jeudi 19 août 2021

C# Reflection reference to another class from inside a DLL

I have 2 classes, one is a DLL and the other is a .cs File and i want to call a Method in the .cs File from the DLL.

DLL

namespace SimpleDebugFormatting
{
    public static class DebugLog
    {
        private static Type debugFormat;
        private static Type DebugFormat
        {
            get
            {
                if (debugFormat == null)
                    return debugFormat = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(_Type => _Type.Name.Contains("DebugFormat"));

                return debugFormat;
            }
        }

        public static List<string> GetMessages(IEnumerable _Parameters)
        {
            return (List<string>)DebugFormat.GetMethod("ConcatMessages", BindingFlags.Static | BindingFlags.NonPublic).Invoke(DebugFormat, new object[] { _Parameters });
        }
    }
}

.cs File

namespace SimpleDebugFormatting
{
    internal static class DebugFormat
    {
        internal static List<string> ConcatMessages(object[] _Messages) { }
    }
}

When both classes are .cs files it all works fine, but when the "DebugLog"-class is a DLL it can't find the "DebugFormat"-class.

When i try to print all types in the DLL's assembly with
"Assembly.GetExecutingAssembly().GetTypes()",
it only shows these 2:

SimpleDebugFormatting.DebugLog
SimpleDebugFormatting.DebugLog+<>c

Why is that so and how can i get it to work?





Aucun commentaire:

Enregistrer un commentaire