Contents tagged with .net code

  • Caching the results from LinqDataSource

    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.

  • Calculator.NET - Calculator that evaluates math expressions

    I'd like to announce the release of a little project I've been working on.  I call it Calculator.NET.  I started this project for a couple reasons.  First, I was annoyed that Windows Vista doesn't come with a better calculator.  Windows XP has Power Calculator, but that doesn't work on Vista.  Next, I was reading a blog about DynCalc by Bart De Smet on how to do mathematical calculations. That gave me the starting point on how to create Calculator.NET. 

  • XML Serializable Generic Dictionary

    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. 

  • MSBuild Community Task Collaboration Project

    I’d like to announce the MSBuild Community Task Collaboration Project.  The project was started by me to form a directory of MSBuild Tasks for use in your build scripts.  The project is also an open source collection of tasks.  The project is broke into 2 web sites. 

  • Generics at Runtime

    namespace GenericTest { [TestClass] public class GenericTest { [TestMethod] public void CreateGenericAtRuntime() { Stopwatch watch = Stopwatch.StartNew(); // define the generic class at runtime Type genericType = typeof(Collection<>).MakeGenericType(typeof(DateTime)); // create an instance of the generic type object instance = Activator.CreateInstance(genericType); watch.Stop();

  • Google Toolbar Spell Check API

    I saw in this post that the Google toolbar could be extracted and looked at. So, I spend an afternoon reverse engineering the spell checker api. The api ends up to be very easy to use. Checking is done with an HTTP post to http://www.google.com/tbproxy/spell?lang=en&hl=en. The xml structure looks like this...
     
    <?xml version="1.0" encoding="utf-8" ?>
    <spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">
        <text>Ths is a tst</text>
    </spellrequest
    >
     
    The response look like ...
     
    <?xml version="1.0" encoding="UTF-8"?>
    <spellresult error="0" clipped="0" charschecked="12">
        <c o="0" l="3" s="1">This Th's Thus Th HS</c>
        <c o="9" l="3" s="1">test tat ST St st</c>
    </spellresult
    >
     
    Tag
    Description
    o
    the offset from the start of the text of the word
    l
    length of misspelled word
    s
    Confidence of the suggestion
    text
    tab delimited list of suggestions
     
    I created a complete C# GoogleSpell library as a demo. The library can be download at http://www.loresoft.com/files/uploads/GoogleSpell.zip
     
    Here is an example on how to use GoogleSpell …
     
    string text = "ths is a tst";
    SpellRequest request = new SpellRequest(text);

    SpellResult result = SpellCheck.Check(request);

    foreach (SpellCorrection correction in result.Corrections)
    {
        Console.WriteLine("Misspelled: {0} ({1}:{2})"
            text.Substring(correction.Offset, correction.Length), 
            correction.Offset, correction.Length);

        foreach(string suggestion in correction.Suggestions)
        {
            Console.WriteLine("    {0}", suggestion);
        }
    }
     
    I plan to develop an ajax web client for the google spell api.  This will be really sweet as it won't require anything to be installed on the sever other then a js file.  I'll post again when I have the web client complete.
     
    ~ Paul