DebuggerTypeProxy for generic type hierarchy
Asked Answered
M

1

5

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:

Menu answered 29/3, 2013 at 16:55 Comment(0)
K
10

Make MatrixSummary a nested class:

[DebuggerTypeProxy(typeof(Matrix<>.MatrixSummary))]
Knoxville answered 4/4, 2013 at 17:59 Comment(3)
Clever idea, thanks! Unfortunately it didn't work for me either. Current Workaround: A non-generic interface implemented by Matrix<T>, and a matching proxy.Moldau
Hmmm... it does work for me. I have it on the base class (i.e. your Generic.Matrix<T>) and it trickles down to the inherited classes as well.Knoxville
Weird, I still can't make it work. My proxy is essentially (child of Matrix<T>): public class MatrixSummary { public MatrixSummary(Matrix<T> m) { P = xy; } public string P {get;set;} } and I've added the attribute exactly as above to Matrix<T>. Did you do anything else? I'm wondering whether some setting or tool like R# is interfering somehow. I'm on VS2012 Update 2, with R# 7.1.2.Moldau

© 2022 - 2024 — McMap. All rights reserved.