Пример #1
0
        /// <summary>
        /// Add a string to the end of the collection.
        /// </summary>
        /// <param name="value">The string to add.</param>
        public void AddString(string value)
        {
            int ol;

            if (_lpwstr)
            {
                ol = (int)(_mem.Length - 2L);
                if (ol <= 0)
                {
                    _mem.Length = 2L;
                    ol          = 0;
                }

                _mem.Length += value.Length + 2;
                QuickCopyObject <string>(IntPtr.Add(_mem.handle, ol), value, (uint)(value.Length * 2));
            }
            else
            {
                int l = SizeDescriptorLength + value.Length * 2;
                if (_mem.Length == 0L)
                {
                    _mem.Length = SizeDescriptorLength;
                }
                ol = (int)_mem.Length;
                switch (SizeDescriptorLength)
                {
                case 1:
                {
                    _mem[0L] = (byte)(_mem[0L] + 1);
                    break;
                }

                case 2:
                {
                    _mem.get_ShortAt(0L);
                    break;
                }

                case 4:
                {
                    _mem.get_UIntegerAt(0L);
                    break;
                }
                }

                _mem.Length += l;
                IntPtr ap;
                IntPtr at;
                ap = IntPtr.Add(_mem.handle, ol);
                at = IntPtr.Add(ap, SizeDescriptorLength);
                MemPtr mm = ap;
                switch (SizeDescriptorLength)
                {
                case 2:
                {
                    mm.set_UShortAt(0L, (ushort)value.Length);
                    break;
                }

                case 4:
                {
                    mm.set_UIntegerAt(0L, (uint)value.Length);
                    break;
                }

                case 8:
                {
                    mm.set_LongAt(0L, value.Length);
                    break;
                }
                }

                QuickCopyObject <string>(at, value, (uint)(value.Length * 2));
            }

            if (!_dynamic)
            {
                _index         = new IntPtr[_count + 1];
                _index[_count] = IntPtr.Add(_mem.handle, ol);
                _count        += 1;
            }
        }
Пример #2
0
        public static object BytesToEnum(byte[] b, Type t)
        {
            SafePtr sp = b;
            int     x  = Blob.BlobTypeSize(Blob.TypeToBlobType(t.GetEnumUnderlyingType()));

            switch (x)
            {
            case 1:
            {
                if (Native.Unsigned(t))
                {
                    return(Enum.ToObject(t, sp[0L]));
                }
                else
                {
                    return(Enum.ToObject(t, sp.get_SByteAt(0L)));
                }

                break;
            }

            case 2:
            {
                if (Native.Unsigned(t))
                {
                    return(Enum.ToObject(t, sp.get_UShortAt(0L)));
                }
                else
                {
                    return(Enum.ToObject(t, sp.get_ShortAt(0L)));
                }

                break;
            }

            case 4:
            {
                if (Native.Unsigned(t))
                {
                    return(Enum.ToObject(t, sp.get_UIntegerAt(0L)));
                }
                else
                {
                    return(Enum.ToObject(t, sp.get_IntegerAt(0L)));
                }

                break;
            }

            case 8:
            {
                if (Native.Unsigned(t))
                {
                    return(Enum.ToObject(t, sp.get_ULongAt(0L)));
                }
                else
                {
                    return(Enum.ToObject(t, sp.get_LongAt(0L)));
                }

                break;
            }
            }

            return(null);
        }