已实现的接口UWP的C#反射检查

时间:2019-03-03 13:12:43

标签: c# reflection uwp

所以我尝试创建一个PluginService,它从一个文件夹加载程序集并检查它是否实现了某个接口。我使用界面

public interface IService
    {
        void Start();
        void Stop();
        void Restart();
    }

和班级

public class Service : IService
    {

        public Service()
        {

        }

        public void Restart()
        {

        }

        public void Start()
        {

        }

        public void Stop()
        {

        }
    }

我从pogorman那里找到了this Question,这对我很有帮助。 编辑: 抱歉,我的意思是此代码段不是DoesTypeImplementInterface

currentAssembly.GetTypes()
                .Where(t => t != typeof(T) && typeof(T).IsAssignableFrom(t))
                .ToList()
                .ForEach(x => implementors.Add((T)Activator.CreateInstance(x)));

0 个答案:

没有答案
相关问题