ArrayEditor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / CompMod / System / ComponentModel / Design / ArrayEditor.cs / 1 / ArrayEditor.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 */ 
namespace System.ComponentModel.Design {
    using System.Runtime.Serialization.Formatters; 
    using System.Runtime.Remoting.Activation;

    using System.Runtime.InteropServices;
    using System.ComponentModel; 

    using System.Diagnostics; 
 
    using System;
    using System.Collections; 
    using Microsoft.Win32;
    using System.Drawing;

    using System.Drawing.Design; 
    using System.Reflection;
    using System.Windows.Forms; 
    using System.Windows.Forms.Design; 
    using System.Windows.Forms.ComponentModel;
 
    /// 
    /// 
    ///    Edits an array of values.
    ///  
    public class ArrayEditor : CollectionEditor {
 
        ///  
        /// 
        ///     
        ///       Initializes a new instance of  using the
        ///       specified type for the array.
        ///    
        ///  
        public ArrayEditor(Type type) : base(type) {
        } 
 
        /// 
        ///  
        ///    
        ///       Gets or
        ///       sets
        ///       the data type this collection contains. 
        ///    
        ///  
        protected override Type CreateCollectionItemType() { 
            return CollectionType.GetElementType();
        } 

        /// 
        /// 
        ///     
        ///       Gets the items in the array.
        ///     
        ///  
        protected override object[] GetItems(object editValue) {
            if (editValue is Array) { 
                Array valueArray = (Array)editValue;
                object[] items = new object[valueArray.GetLength(0)];
                Array.Copy(valueArray, items, items.Length);
                return items; 
            }
            else { 
                return new object[0]; 
            }
        } 

        /// 
        /// 
        ///     
        ///       Sets the items in the array.
        ///     
        ///  
        protected override object SetItems(object editValue, object[] value) {
            if (editValue is Array || editValue == null) { 
                Array newArray = Array.CreateInstance(CollectionItemType, value.Length);
                Array.Copy(value, newArray, value.Length);
                return newArray;
            } 
            return editValue;
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK