Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Attributes » Downloads
 
Add your own
alternative version
Go to top

Make NDoc compile the code examples contained in your documentation using NLiterate

, 26 Apr 2004
An utility that merges and recompiles the examples in your documentation using NDoc.
// The MIT License
// Copyright (c) 2004 Jonathan de Halleux
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in 
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.

namespace NLiterate
{
    /// <summary>
    /// A collection of elements of type <see cref="CodeSnippet"/>.
    /// </summary>
    public class CodeSnippetCollection: System.Collections.CollectionBase
    {
        /// <summary>
        /// Initializes a new empty instance of the <see cref="CodeSnippetCollection"/> class.
        /// </summary>
        public CodeSnippetCollection()
        {
            // empty
        }

        /// <summary>
        /// Adds an instance of type <see cref="CodeSnippet"/> to the end of this <see cref="CodeSnippetCollection"/> .
        /// </summary>
        /// <param name="value">
        /// The <see cref="CodeSnippet"/> to be added to the end of this <see cref="CodeSnippetCollection"/> .
        /// </param>
        public virtual void Add(CodeSnippet value)
        {
            this.List.Add(value);
        }

        /// <summary>
        /// Determines whether a specfic <see cref="CodeSnippet"/> value is in this <see cref="CodeSnippetCollection"/>.
        /// </summary>
        /// <param name="value">
        /// The <see cref="CodeSnippet"/> value to locate in this <see cref="CodeSnippetCollection"/>.
        /// </param>
        /// <returns>
        /// true if value is found in this <see cref="CodeSnippetCollection"/>;
        /// false otherwise.
        /// </returns>
        public virtual bool Contains(CodeSnippet value)
        {
            return this.List.Contains(value);
        }

        /// <summary>
        /// Return the zero-based index of the first occurrence of a specific value
        /// in this <see cref="CodeSnippetCollection"/>
        /// </summary>
        /// <param name="value">
        /// The <see cref="CodeSnippet"/> value to locate in the <see cref="CodeSnippetCollection"/>.
        /// </param>
        /// <returns>
        /// The zero-based index of the first occurrence of the _ELEMENT value if found;
        /// -1 otherwise.
        /// </returns>
        public virtual int IndexOf(CodeSnippet value)
        {
            return this.List.IndexOf(value);
        }

        /// <summary>
        /// Inserts an element into the <see cref="CodeSnippetCollection"/> at the specified index
        /// </summary>
        /// <param name="index">
        /// The index at which the <see cref="CodeSnippet"/> is to be inserted.
        /// </param>
        /// <param name="value">
        /// The <see cref="CodeSnippet"/> to insert.
        /// </param>
        public virtual void Insert(int index, CodeSnippet value)
        {
            this.List.Insert(index, value);
        }

        /// <summary>
        /// Gets or sets the <see cref="CodeSnippet"/> at the given index in this <see cref="CodeSnippetCollection"/>.
        /// </summary>
        public virtual CodeSnippet this[int index]
        {
            get
            {
                return (CodeSnippet) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }

        /// <summary>
        /// Removes the first occurrence of a specific <see cref="CodeSnippet"/> from this <see cref="CodeSnippetCollection"/>.
        /// </summary>
        /// <param name="value">
        /// The <see cref="CodeSnippet"/> value to remove from this <see cref="CodeSnippetCollection"/>.
        /// </param>
        public virtual void Remove(CodeSnippet value)
        {
            this.List.Remove(value);
        }

        /// <summary>
        /// Type-specific enumeration class, used by CodeSnippetCollection.GetEnumerator.
        /// </summary>
        private class Enumerator: System.Collections.IEnumerator
        {
            private System.Collections.IEnumerator wrapped;

            public Enumerator(CodeSnippetCollection collection)
            {
                this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
            }

            public CodeSnippet Current
            {
                get
                {
                    return (CodeSnippet) (this.wrapped.Current);
                }
            }

            object System.Collections.IEnumerator.Current
            {
                get
                {
                    return (CodeSnippet) (this.wrapped.Current);
                }
            }

            public bool MoveNext()
            {
                return this.wrapped.MoveNext();
            }

            public void Reset()
            {
                this.wrapped.Reset();
            }
        }

        /// <summary>
        /// Returns an enumerator that can iterate through the elements of this <see cref="CodeSnippetCollection"/>.
        /// </summary>
        /// <returns>
        /// An object that implements <see cref="System.Collections.IEnumerator"/>.
        /// </returns>        
        public new virtual System.Collections.IEnumerator GetEnumerator()
        {
            return new CodeSnippetCollection.Enumerator(this);
        }
    }	
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jonathan de Halleux
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 27 Apr 2004
Article Copyright 2004 by Jonathan de Halleux
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid