The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ANN: Optimized automatic control binder is out - and its fast!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
ANN: Optimized automatic control binder is out - and its fast! Posted: Sep 23, 2004 2:02 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: ANN: Optimized automatic control binder is out - and its fast!
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
Last month I posted about a cool way we came up with to automatically bind all the controls on our application forms to various data sources. That solution was cool, but it was slow. Because it used binding. And because I made it in like an hour, and because I didn't optimize the various loops inside it and so on..
 
Well - here's the new - optimized version of the ControlBinder class.
By optimized I mean that with the old class we ran it on a form with about 200 controls and it took about 5 seconds to bind. With the new version it takes 0.6 seconds on the first run. In the next runs (that is - you closed the form and then reopened it and then called bind again) it takes 0.3 seconds. Yeah - its cool and now its even usable!
  • Caching, Caching, Caching: On the first run on the form all attributes, member infos and bindable controls are saved to a cache hidden from the developer. On the next runs the cache is used to bind controls, without the need to use reflection more than once on each form. This way even if you closed the form and reopened it - binding it again will be much faster.
  • Categories: Bind multiple controls on the form to multiple data sources by providing a "category" attribute value and calling "bind" specifying a category and a data source.
  • ControlCoordinate class: this one was a bitch. There's no easy way to find a control on a form in win forms 1.1. That is - each control's Index on the containing control can be retrieved, but you can't use that index later to find the control on the form instance. This is because control collections are hierarchical - so if you want to find a control which resides in a control panel on your form you'd have to do something like form.Controls[0].Controls[0] to get that control. Easy huh? Well - I made a ControlCoordinate class which can take any control and save a "marker" to it, which can later be retrieved easily by calling Coordinate.FindControl(form). Very simple and easy. Its all in there. Coordinates are saved in an inner cache to so that after we know what controls actually have various attributes we can ignore all the other controls and zoom in directly on each control using its coordinate. Phew. That took a while to find out how to do (at first I did not believe the solution has to be this in-elegant)
  • BindToValueList: You can bind combos as well with this special attribute
  • Extensibility: Its easy to create your own attributes and control types with special bindings. The object model contains an extensible abstract factory pattern of specific control binder implementations per attribute type or control type.
the download contains a single class file and also a simple binding demo with Northwind database. Very easy and simple. Have fun!

Read: ANN: Optimized automatic control binder is out - and its fast!

Topic: MyXaml and Xamlon Compared Previous Topic   Next Topic Topic: ASP.NET 2.0 Partial Trust Web Sites

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use