I wanted to be able to cache the results of a query from the LinqDataSource that was used in multiple places on the page. I whipped up this little class to do the work of caching for me. The class, LinqCacheDataSource, handles the Selecting and Selected events. The Selected handler inserts the result of the query into cache. The Selecting handler gets the result from the cache. If it doesn't find the result, the query runs as normal. The caching will only work for selecting data. It works great for dropdowns and other fairly static data.
The following query extension will make paging a query more natural then skip and take. Simply append Paginate(page, pageSize) to your query.
For some reason, the generic Dictionary in .net 2.0 is not XML serializable. The following code snippet is a xml serializable generic dictionary. The dictionary is serialzable by implementing the IXmlSerializable interface.
Here is a code snippet that is equivalent to the windows API PathRelativePathTo as native c#. The function creates a relative path from one file or folder to another.
Here is a little test code that demonstrates how to use Generics at runtime. The code has two tests. The first test shows how to create a Generic Class at runtime. The second shows how to call a Generic method. Keep in mind that when using generics at runtime, there will be a reflection performance hit.
~ Paul
Here is the handy Stopwatch class from .net 2.0 framework back ported .net 1.1. Enjoy…
Here is a useful code snippet to convert the tense of a word from single to plural and vise versa. The code uses a series of regular expression to examine the word and convert it using the correct grammar.
In my work with the RichTextBox control, I've often run into this bug in the RichEdit control. You can read more about this bug by looking at Microsoft's knowledge base article - 812943. If you are unable to get the latest Riched20.dll then you can get around the problem using the following code …