3
我不知道,因爲沒有辦法如何實現在C#泛型裝飾類(是嗎?)是這樣的:一般裝飾在C#
public class Decorator<TDecoratorIterface> : TDecoratorInterface
{
public TDecoratorInterface Component {get; private set;}
protected Decorator(TDecoratorInterface component)
{
Component = component;
}
}
使用這樣的:
public interface IDogDecorator
{
void Bark();
}
public class Dog : IDogDecorator
{
public void Bark()
{
Console.Write("I am a dog");
}
}
public class StinkingDog : Decorator<IDogDecorator>
{
public StinkingDog(IDogDecorator dog):base(dog)
{
}
public void Bark()
{
Component.Bark();
Console.WriteLine(" and I stink");
}
}
能這樣的事情可以通過PostSharp或.NET的其他AOP框架進行管理?
感謝來回你的答案,我花了半天時間嘗試沒有成功創建這樣一個結構,所以任何幫助appreciatted :)