How to check typeof parameters in method with help code contracts?
I need check type argument in method
How to check typeof parameters in method with help code contracts?
I need check type argument in method
How about
public void MyMethod(object parameter)
{
if (parameter.GetType() == typeof(Int32))
{
//Do some stuff
}
}
In continuation to your other question
class ManagerCar : IBlalba
{
public void Render(IViewTemplate template)
{
if (template.GetType() == typeof(CarViewTemplate))
{
//Do some stuff
}
}
}
I think this should do it:
Contract.Requires(yourParameter is YourType);
Although I have to say this sounds like a pretty bad idea, unless you're required to use underspecified types for interface implementation reasons.