je les classes suivantes définies:Obtenez la vue correspondant à un type de Windsor
public interface IShapeView
{
void DoSomethingWithShape(Shape shape);
}
public interface IShapeView<T> where T : Shape
{
void DoSomethingWithShape(T shape);
}
public class CircleView : IShapeView<Circle>, IShapeView
{
public void DoSomethingWithShape(Circle shape)
{
MessageBox.Show("Circle:" + shape.Radius);
}
void IShapeView.DoSomethingWithShape(Shape shape)
{
DoSomethingWithShape((Circle)shape);
}
}
public class Circle : Shape
{
public Circle()
{
Radius = 1.0;
}
public double Radius { get; set; }
}
Et l'inscription suivante:
container.Register(Component.For<IShapeView<Circle>>().ImplementedBy<CircleView>());
Y at-il une méthode que je peux appeler pour résoudre une vue quand je n'ai que le type de la forme? Ou ai-je besoin d'utiliser la réflexion pour créer les arguments de type générique pour obtenir le type correct de IShapeView que je veux? Vous cherchez quelque chose comme ceci:
Type shapeType = typeof(Circle);
IShapeView view = (IShapeView) container.SomeResolveMethod(shapeType, typeof(IShapeView<>));
Merci, c'est ce que je cherchais! –