Question

I'm trying to write a debugger type proxy/surrogate for matrices and vectors in Math.NET Numerics, so the debugger shows more useful information (also in F# FSI). The type hierarchy is as follows:

  • Generic.Matrix<T>
  • Double.Matrix : Generic.Matrix<double>
  • Double.DenseMatrix : Double.Matrix

What works

Non-generic proxy with closed, generic type. It also works the same way if instead of Matrix<double> the constructor would accept a Double.Matrix or a Double.DenseMatrix.

public class MatrixSummary
{
    public MatrixSummary(Matrix<double> matrix) { }
    // ...
}

Then, decorate Double.DenseMatrix with:

[DebuggerTypeProxy(typeof(MatrixSummary))]

What I'd like to work

I'd prefer not having to implement a separate proxy for every type, so let's make it generic:

public class MatrixSummary<T> where T : ...
{
    public MatrixSummary(Matrix<T> matrix) { }
    // ...
}

Then, decorate Double.DenseMatrix with:

[DebuggerTypeProxy(typeof(MatrixSummary<>))]

Or maybe closed with:

[DebuggerTypeProxy(typeof(MatrixSummary<double>))]

And/or maybe also add that attribute to the base classes if needed.

None of these work e.g. when debugging Unit Tests, even though the documentation says it is supposed to work when declaring the attribute with an open generic type (i.e. MatrixSummary<>). After all it also works fine with List<T> etc.

Any ideas?

Related:

Was it helpful?

Solution

Make MatrixSummary a nested class:

[DebuggerTypeProxy(typeof(Matrix<>.MatrixSummary))]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top