Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DebuggerTypeProxy for generic type hierarchy

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:

  • Diagnosing why DebuggerTypeProxy attributes are not working
  • How can I have my DebuggerTypeProxy target class inherit from base proxies?
  • http://msdn.microsoft.com/en-us/library/d8eyd8zc.aspx
like image 830
Christoph Rüegg Avatar asked Mar 29 '13 16:03

Christoph Rüegg


1 Answers

Make MatrixSummary a nested class:

[DebuggerTypeProxy(typeof(Matrix<>.MatrixSummary))]
like image 91
Jeffrey Sax Avatar answered Oct 03 '22 16:10

Jeffrey Sax