我想通过这一检验方法——任何人都想如何这样做?
public class Something
{
public string Name {get; set}
}
public interface IWithId
{
public Guid Id {get; set}
}
public class IdExtender
{
public static Object Extend(object toExtend)
{
...?
}
}
public class Tests
{
[Test]
public void Should_extend_any_object()
{
var thing = new Something { Name = "Hello World!"};
var extended = IdExtender.Extend(thing);
Assert.IsTrue(extended is IWithId);
Assert.IsTrue(extended.Id is Guid);
Assert.IsTrue(extened.Name == "Hello World!");
}
}
我猜想,像这样的东西可以用城堡动态代理、lin子、etc,但如何做?