如果用户传入一个接口,并且我想用它动态地创建一个类,是否可以使用对象表达式来实现?也就是说,给定一个接口:
type IMyInterface =
abstract Perform : Unit -> Unit
有没有办法说:
obj = {
new IMyInterface with
member this.Perform() = Console.WriteLine("Perform this action")
}
如果没有,是否有一种 non-Reflection.Emit 这样做的方式?