Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C#

Resolving Symbolic References in a CodeDOM (Part 7)

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
2 Dec 2012CDDL12 min read 19.4K   509   14  
Resolving symbolic references in a CodeDOM.
// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System;

namespace Nova.Utilities
{
    /// <summary>
    /// Extension and helper methods for <see cref="Array"/>s.
    /// </summary>
    public static class ArrayUtil
    {
        #region /* STATIC HELPER METHODS */

        // The following methods would be redundant with those in CollectionUtil:
        //public static bool IsEmpty(Array thisArray)
        //public static bool NotEmpty(Array thisArray)
        //public static int NNLength(Array thisArray)  // Same as NNCount in CollectionUtil

        /// <summary>
        /// Check if an array contains the specified item.
        /// </summary>
        /// <typeparam name="T">The type of the items in the array.</typeparam>
        /// <param name="thisArray">The array being searched.</param>
        /// <param name="item">The item being searched for.</param>
        /// <returns>True if the array contains the item, otherwise false.</returns>
        public static bool Contains<T>(T[] thisArray, T item)
        {
            foreach (T member in thisArray)
            {
                if (member.Equals(item))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Add the contents of the 2nd array to the 1st one.
        /// If the 1st array is null, the 2nd array will be assigned to it.
        /// </summary>
        /// <param name="array1">The 1st array (can be null).</param>
        /// <param name="array2">The 2nd array (can be null).</param>
        /// <typeparam name="T">The element type of the arrays.</typeparam>
        public static void Add<T>(ref T[] array1, T[] array2)
        {
            if (array1 == null || array1.Length == 0)
                array1 = array2;
            else if (array2 != null && array2.Length != 0)
            {
                int oldLength = array1.Length;
                Array.Resize(ref array1, oldLength + array2.Length);
                array2.CopyTo(array1, oldLength);
            }
        }

        #endregion
    }
}

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 Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
United States United States
I've been writing software since the late 70's, currently focusing mainly on C#.NET. I also like to travel around the world, and I own a Chocolate Factory (sadly, none of my employees are oompa loompas).

Comments and Discussions