Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / C#

Code Spelling Checker Extension for Visual Studio 2010 (VSX)

Rate me:
Please Sign up or sign in to vote.
4.98/5 (43 votes)
7 Apr 2010CPOL6 min read 111.5K   2.4K   74  
Building a spelling checker for source code as an extension for Visual Studio 2010
using System;
using System.Collections.Generic;


namespace DigitalSamurai.SpellSharp.InputProcessing
{
    public struct DocumentPosition : IComparable<DocumentPosition>, IEquatable<DocumentPosition>
    {
        #region public int Line { get; }
        private int _Line;

        public int Line
        {
            get { return _Line; }
        }
        #endregion

        #region public int Column { get; }
        private int _Column;

        public int Column
        {
            get { return _Column; }
        }
        #endregion


        public DocumentPosition (int line, int column)
        {
            _Line = line;
            _Column = column;
        }


        public override bool Equals (object other)
        {
            if (other is DocumentPosition)
            {
                return Equals ((DocumentPosition) other);
            }

            return false;
        }

        public override int GetHashCode ()
        {
            return Line ^ Column;
        }

        public override string ToString ()
        {
            return string.Format ("{{ Line : {0}; Column : {1} }}", Line, Column);
        }


        public static int Compare (DocumentPosition a, DocumentPosition b)
        {
            int result = Comparer<int>.Default.Compare (a.Line, b.Line);
            if (result != 0)
            {
                return result;
            }

            return Comparer<int>.Default.Compare (a.Column, b.Column);
        }

        public int CompareTo (DocumentPosition other)
        {
            return Compare (this, other);
        }

        public bool Equals (DocumentPosition other)
        {
            return Compare (this, other) == 0;
        }


        public DocumentPosition Increment (int lineIncrement, int columnIncrement)
        {
            return new DocumentPosition
            (
                Line + lineIncrement,
                Column + columnIncrement
            );
        }


        public static bool operator < (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) < 0;
        }

        public static bool operator <= (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) <= 0;
        }

        public static bool operator == (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) == 0;
        }

        public static bool operator != (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) != 0;
        }

        public static bool operator >= (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) >= 0;
        }

        public static bool operator > (DocumentPosition a, DocumentPosition b)
        {
            return Compare (a, b) > 0;
        }
    }
}

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
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions