Contents tagged with Reflection

  • How to create plugins that can be loaded/unloaded

    Hello everybody,

    today I want to show sample of code that you can use for your plugins.

    Sometime it can happen that you have some application with it's dlls and you can decide to make ad hoc dlls.

    In order to demonstrate how to do it I prepared following code:

    Create first class library as BaseLib:

    using System;

    namespace BaseClass

    {

        public class BaseClass : MarshalByRefObject

        {

            public virtual bool IsProcessable(string message)

            {

                return true;

            }

            public virtual void Process(string message)

            {

                

            }

        }

    }

    Then create following implementation:

    using System;

    namespace Ext1

    {

        public  … more

  • How to check if type in Assembly implements particular Interface

    Hello everybody,

    today I want to give sample of reading available types from dll .net assembly, check if at least one of them implements interface, and if implements then to create instance of that type and return it. 

    So, imagine you have such interface declaration in your code:

    public interface ILogger

        {

            /// <summary>

            /// Convert <see cref="LoggerMessage"/> to string based on the formats specified.

            /// </summary>

            /// <param name="message">The message to be converted.</param>

            /// <returns>Converted <paramref name="message"/>.</returns>

            LoggerMessage Handle(LoggerMessage message);

            bool Handlable(LoggerMessage message); … more