0

The problem I'm facing might be stupid, but I've never encountered it, so I guess I need some help. I'm learning how to use a Debug Visualizer. I've created one: DebuggerSide.cs located in CarGarageVisualizer namespace.

I wanted the type of CarGarage<T> to be seen in this visualizer when debugging instance of this, so I've put following attributes to the class:

    [DebuggerVisualizer(typeof(CarGarageVisualizer.DebuggerSide))]
    [Serializable]
    public class CarGarage<T>:IEnumerable<T>
        where T : Car,new()
    {
    ...
    }

Now, to add first attribute I needed to add reference to CarGarageVisualizer that contains the DebuggerSide class. That's OK. But now, in my DebuggerSide's overriden method Show() I wanted to explicitly cast object gained from the objectProvider argument to the type of CarGarage<T>. But to be able to do this I would need to reference the CarGarageLibrary that contains the definition of this. And as I said I can't do that, because I get the error about recursive reference.

From other post on this subject, I know it's a bad practice. But, I don't want to copy the CarGarage<T> class to my Visualizer namespace (that would solve the problem, but I'm not sure if it's the right thing to do) unless there's not a better option.

Can anybody help me with this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Paweł Poręba
  • 1,084
  • 1
  • 14
  • 37

2 Answers2

1

You should put the CarGarageVisualizer.DebuggerSide in a separate library that will and can be referenced by both.

Didn't get it correctly, I think.

What about, putting the CarGarage<T> in a separate library.

library CarGarage:
[Serializable]
public class CarGarage<T>:IEnumerable<T>
    where T : Car,new()
{
...
}

library DebugVis:  (uses CarGarage)
DebuggerSide....

library app:  (uses CarGarage)
[DebuggerVisualizer(typeof(CarGarageVisualizer.DebuggerSide))]
public class CarGarageImpl<T> : CarGarage<T> { }
Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57
  • I don't get the sense of it. I've used the template to create the Debug Visualizer and now I need to put it to another library? That seems just stupid. – Paweł Poręba Nov 11 '15 at 13:39
  • Sorry, I've forgotten to accept:) Ofc that was the correct answer, it should be kept in a separate library, I messed up on that. Thanks! – Paweł Poręba Dec 05 '15 at 20:19
0

You can use the DebuggerVisualizerAttribute constructor overload that takes string containing the fully qualified type name of the visualizer like this

public static class MyVisualizers
{
    public const string AssemblyRef = @"MyVisualizers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
}

[DebuggerVisualizer("MyVisualizersNamespace.CarGarageVisualizer+DebuggerSide, " + MyVisualizers.AssemblyRef)]
[Serializable]
public class CarGarage<T>:IEnumerable<T>
    where T : Car,new()
{
    ...
}
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343