ASP.NET data binding: Track and provide type information


I have a rather large web forms project. To catch more errors at compile time, I am using generics to create strongly typed controls for data binding, inspired by 's CodeProject article about a strongly typed asp:Repeater (

It works by creating two subclasses of Repeater: TypedRepeater and TypedRepeater<T>. TypedRepeater is provided with a property DataItemTypeName, which its custom ControlBuilder resolves to a type, and then tells the compiler to create a TypedRepeater<T> instead. With a little extra work, Container.DataItem is typed as T in data binding expressions.

I have also reused the idea by creating strongly typed GridView and TemplateField subclasses where Container.DataItem also is typed as T. Additionally, my gridview control builder extracts expressions from the two-way data binding expression given to Bind("MyProperty") and make a compile time check that MyProperty is indeed a valid expression on T.

<my:TypedGridView runat="server" DataItemTypeName="MyApp.User">
          <my:TypedTemplateField HeaderText="Name">
                    <asp:TextBox ID="textBox1" Text='<%# Bind("Name") %>' runat="server" />
          <my:TypedTemplateField HeaderText="Last login">
                    <my:DateTimeDisplay ID="datePicker1" DateTime='<%# Container.DataItem.LastLogin %>' runat="server" />

This means that I have nice compile time checks of all data binding expressions. Unfortunately, ReSharper is not aware of this type information. I want to change that somehow. ReSharper does not support control builders, so I want to make a plugin to somehow make it understand.

As I see it, my plugin needs to do four things:
1. Recognize that the property DataItemTypeName on TypedGridView is a type name, validate it and preferably provide intellisense/autocompletion.
2. Tell ReSharper that the gridview tag actually resolves to a TypedGridView<T>.
3. Tell ReSharper that the TypedTemplateField tags actually resolves to TypedTemplateField<T>.
4. Validate the string argument to Bind as being a valid property/expression on T. Preferably also tell ReSharper about it in such a way that it can find the usage and perform refactorings on it (rename).

I would really appreciate some input on how to go about doing this, ie. pointers on how to hook into ReSharper in an appropriate way and provide the information.

I have been playing with Hadi Hariri's plugin examples and browsing the ReSharper API, so I have at least basic knowledge about ReSharper plugin development.


Please sign in to leave a comment.