System.Runtime.Serialization.Formatters.Binary.Converter.CreatePrimitiveArray C# (CSharp) Method

CreatePrimitiveArray() static private method

static private CreatePrimitiveArray ( InternalPrimitiveTypeE code, int length ) : Array
code InternalPrimitiveTypeE
length int
return System.Array
        internal static Array CreatePrimitiveArray(InternalPrimitiveTypeE code, int length)
        {
            switch (code)
            {
                case InternalPrimitiveTypeE.Boolean: return new bool[length];
                case InternalPrimitiveTypeE.Byte: return new byte[length];
                case InternalPrimitiveTypeE.Char: return new char[length];
                case InternalPrimitiveTypeE.Decimal: return new decimal[length];
                case InternalPrimitiveTypeE.Double: return new double[length];
                case InternalPrimitiveTypeE.Int16: return new short[length];
                case InternalPrimitiveTypeE.Int32: return new int[length];
                case InternalPrimitiveTypeE.Int64: return new long[length];
                case InternalPrimitiveTypeE.SByte: return new sbyte[length];
                case InternalPrimitiveTypeE.Single: return new float[length];
                case InternalPrimitiveTypeE.TimeSpan: return new TimeSpan[length];
                case InternalPrimitiveTypeE.DateTime: return new DateTime[length];
                case InternalPrimitiveTypeE.UInt16: return new ushort[length];
                case InternalPrimitiveTypeE.UInt32: return new uint[length];
                case InternalPrimitiveTypeE.UInt64: return new ulong[length];
                default: return null;
            }
        }

Usage Example

Exemplo n.º 1
0
 private void ReadArrayAsBytes(ParseRecord pr)
 {
     if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Byte)
     {
         pr.PRnewObj = (object)this.ReadBytes(pr.PRlengthA[0]);
     }
     else if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Char)
     {
         pr.PRnewObj = (object)this.ReadChars(pr.PRlengthA[0]);
     }
     else
     {
         int num1 = Converter.TypeLength(pr.PRarrayElementTypeCode);
         pr.PRnewObj = (object)Converter.CreatePrimitiveArray(pr.PRarrayElementTypeCode, pr.PRlengthA[0]);
         Array dst  = (Array)pr.PRnewObj;
         int   num2 = 0;
         if (this.byteBuffer == null)
         {
             this.byteBuffer = new byte[4096];
         }
         while (num2 < dst.Length)
         {
             int num3 = Math.Min(4096 / num1, dst.Length - num2);
             int num4 = num3 * num1;
             this.ReadBytes(this.byteBuffer, 0, num4);
             Buffer.InternalBlockCopy((Array)this.byteBuffer, 0, dst, num2 * num1, num4);
             num2 += num3;
         }
     }
 }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.Converter::CreatePrimitiveArray