I can get type of constructor parameter like this:
Type type = paramInfo.ParameterType;
Now I want to create stub object from this type. Is is possible? I tried with autofixture:
public TObject Stub<TObject>()
{
Fixture fixture = new Fixture();
return fixture.Create<TObject>();
}
.. but it doesn't work:
Type type = parameterInfo.ParameterType;
var obj = Stub<type>();//Compile error! ("cannot resolve symbol type")
Could you help me out?
Type
) and generics (<T>
) is ... kinda painful (and slow) - you can do it (with yet more reflection) - but it is best avoided if at all possible... – Alphorn