Buffer 类 (public static class)
下面就是 mcs/class/corlib/System/Buffer.cs:
001: // 002: // System.Buffer.cs 003: // 004: // Authors: 005: // Paolo Molaro (lupus@ximian.com) 006: // Dan Lewis (dihlewis@yahoo.co.uk) 007: // 008: // (C) 2001 Ximian, Inc. http://www.ximian.com 009: // 010: 011: // 012: // Copyright (C) 2004 Novell, Inc (http://www.novell.com) 013: // 014: // Permission is hereby granted, free of charge, to any person obtaining 015: // a copy of this software and associated documentation files (the 016: // "Software"), to deal in the Software without restriction, including 017: // without limitation the rights to use, copy, modify, merge, publish, 018: // distribute, sublicense, and/or sell copies of the Software, and to 019: // permit persons to whom the Software is furnished to do so, subject to 020: // the following conditions: 021: // 022: // The above copyright notice and this permission notice shall be 023: // included in all copies or substantial portions of the Software. 024: // 025: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 026: // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 027: // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 028: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 029: // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 030: // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 031: // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 032: // 033: 034: using System.Runtime.CompilerServices; 035: using System.Runtime.InteropServices; 036: 037: namespace System { 038: [ComVisible (true)] 039: public static class Buffer { 040: 041: public static int ByteLength (Array array) 042: { 043: // note: the other methods in this class also use ByteLength to test for 044: // null and non-primitive arguments as a side-effect. 045: 046: if (array == null) 047: throw new ArgumentNullException ("array"); 048: 049: int length = ByteLengthInternal (array); 050: if (length < 0) 051: throw new ArgumentException (Locale.GetText ("Object must be an array of primitives.")); 052: 053: return length; 054: } 055: 056: public static byte GetByte (Array array, int index) 057: { 058: if (index < 0 || index >= ByteLength (array)) 059: throw new ArgumentOutOfRangeException ("index", Locale.GetText( 060: "Value must be non-negative and less than the size of the collection.")); 061: 062: return GetByteInternal (array, index); 063: } 064: 065: public static void SetByte (Array array, int index, byte value) 066: { 067: if (index < 0 || index >= ByteLength (array)) 068: throw new ArgumentOutOfRangeException ("index", Locale.GetText( 069: "Value must be non-negative and less than the size of the collection.")); 070: 071: SetByteInternal (array, index, value); 072: } 073: 074: public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count) 075: { 076: if (src == null) 077: throw new ArgumentNullException ("src"); 078: