Mono源代码学习笔记:Console类(三)

本文详细解析了Mono中的Buffer类,包括其提供的高效操作数组的静态方法,并探讨了IConsoleDriver接口及其内部实现NullConsoleDriver类,阐述了它们在控制台交互中的作用和设计模式的应用。
摘要由CSDN通过智能技术生成

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:  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值