Click here to Skip to main content
15,886,864 members
Articles / Programming Languages / Javascript

JSLint.VS - JavaScript Verifier for Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.88/5 (29 votes)
9 Nov 2009CPOL5 min read 193.8K   964   82  
A Visual Studio add-in that uses JSLint to verify JavaScript files that are part of a solution.
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System;

/// <summary>
/// Deserializes/Serializes IDictionary from/to hard disk.
/// Parts snached from http://blogs.msdn.com/psheill/archive/2005/04/09/406823.aspx
/// </summary>
public class DictionarySerializer
{
    public static string Serialize(IDictionary dictionary)
    {
        List<Entry> entries = new List<Entry>(dictionary.Count);
        foreach (object key in dictionary.Keys)
        {
            entries.Add(new Entry(key, dictionary[key]));
        }

        XmlSerializer serializer = new XmlSerializer(typeof(List<Entry>));
        using (StringWriter sw = new StringWriter())
        {
            serializer.Serialize(sw, entries);
            return sw.ToString();
        }
    }

    public static void Deserialize(string toRead, IDictionary dictionary)
    {
        if (string.IsNullOrEmpty(toRead))
        {
            return;
        }

        dictionary.Clear();
        XmlSerializer serializer = new XmlSerializer(typeof(List<Entry>));
        List<Entry> list = null;

        using (StringReader sr = new StringReader(toRead))
        {
            list = (List<Entry>)serializer.Deserialize(sr);
        }

        foreach (Entry entry in list)
        {
            dictionary[entry.Key] = entry.Value;
        }
    }

    public class Entry
    {
        public object Key;
        public object Value;

        public Entry()
        {
        }

        public Entry(object key, object value)
        {
            Key = key;
            Value = value;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
United States United States
If you liked this article, consider reading other articles by me. For republishing article on other websites, please contact me by leaving a comment.

Comments and Discussions