Feature request: Provide a strongly typed variant of the Property constraint
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Framework |
Triaged
|
Medium
|
Unassigned |
Bug Description
[Issue now tracked at https:/
Currently, NUnit supports a number of generic constraints that define the type of the tested expression at compile time (if they succeed): Is.TypeOf<T>(), Is.AssignableTo
Those constraint factory methods currently return instances of non-generic expression types (e.g., ExactTypeConstr
Passing the property name as string is bad as an invalid name will not trigger a compile-time error and as automated refactorings (e.g., renaming the property) will not take notice of the property name.
Therefore, change TypeOf<T>, AssignableTo<T>, and InstanceOf<T> to return generic subclasses of the contraint types (e.g., ExactTypeConstr
Here is what the code could look like for NUnit 2.6 (with non-breaking changes).
public class ExactTypeConstr
{
public new ConstraintExpre
}
public class ConstraintExpre
{
public new ConstraintExpre
public new ConstraintExpre
// ...
public ResolvableConst
}
public class ResolvableConst
{
public new ConstraintExpre
public new ConstraintExpre
}
That way, one could write constraints similar to:
Is.TypeOf<
Changed in nunitv2: | |
status: | New → Triaged |
importance: | Undecided → Medium |
milestone: | none → 2.6.0 |
tags: | added: feature |
tags: | added: framework |
description: | updated |
tags: | added: github |
This is a good idea but requires .NET 3.5 to use Expression and also has some ramifications on how ContraintExpres sions work in general. Pushing it to NUnit 3.0, where we will have separate builds for .NET 2.0, 3.5 and 4.0.