Resolving an unknown type

Jan 30, 2009 at 1:53 PM
public interface IView<T>
{
  void DoSomething(T viewData);
}

public void Meh(object viewData)
{
  Type viewType = typeof(IView<>).MakeGenericType(new Type[] { viewData.GetType(); });
  var implementor = Container.Resolve(viewType);

  //How do I call DoSomething on the implementor?
}


Pete
Jan 30, 2009 at 6:02 PM
At this point, the type of the variable implementor is type Object. If you want to call DoSomething you'll have to use reflection. This would have happened even if you didn't have the container in there.

Jan 30, 2009 at 7:14 PM
I realise that.  The point of my post is this

foreach(AbstractType current in this.Children)
{
  var implementor = Container.Resolve<IProcessor<AbstractType>>();
  implementor.Process(current);
}

There is no way for me to get the correct IProcessor for the current child, I will always get a processor for the abstract type, and that is not what I want.  Is there a way for me to resolve to IProcessor<ConcreteDescendant> instead?

Pete