我想根据类属性注册和解析动态加载的类型.我的代码如下:
自定义类属性:
[MetadataAttribute]
public class FooIdentifier : Attribute
{
public string Identifier { get; private set; }
public FooIdentifier(string identifier)
{
this.Identifier = identifier;
}
}
Run Code Online (Sandbox Code Playgroud)
我的抽象基类
public abstract class Base
{
public abstract bool Execute(object param);
public bool Run(object param = null)
{
//...
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我的实现类型
[FooIdentifier("230")]
public class Child1 : Base
{
public override bool Execute(object param)
{
throw new NotImplementedException();
}
}
[FooIdentifier("250")]
public class Child2 : Base
{
public override bool Execute(object param) …Run Code Online (Sandbox Code Playgroud)