How can I change color of lines in Visual Studio 2010 based on some custom pattern? For example, I want to change color of all lines that start with logger.
. Is it possible at all?
I have ReSharper 5 installed too.
How can I change color of lines in Visual Studio 2010 based on some custom pattern? For example, I want to change color of all lines that start with logger.
. Is it possible at all?
I have ReSharper 5 installed too.
I wrote up a quick little extension to do this; since you'll very likely want to modify it, you should grab the source. The important part is the code in LayoutChanged
:
void ViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
IWpfTextView view = sender as IWpfTextView;
var adornmentLayer = view.GetAdornmentLayer("HighlightLines");
foreach (var line in e.NewOrReformattedLines)
{
if (line.Extent.GetText().StartsWith("logger.", StringComparison.OrdinalIgnoreCase))
{
Rectangle rect = new Rectangle()
{
Width = view.ViewportWidth + view.MaxTextRightCoordinate,
Height = line.Height,
Fill = Brushes.AliceBlue
};
Canvas.SetTop(rect, line.Top);
Canvas.SetLeft(rect, 0);
adornmentLayer.AddAdornment(line.Extent, null, rect);
}
}
}
To build/run this, you'll need to:
Fill = Brushes.AliceBlue
line.if
expression.[ContentType]
attribute. The "Content Types" section of this msdn page lists out some of the common ones.