Exemple #1
0
        public static async Task <int> BufferAsync(this HGlobalCache <char> hGCache, TextReader textReader)
        {
            int offset = 0;

Loop:

            if (offset >= hGCache.Count)
            {
                hGCache.Expand(1218);
            }

            IntPtr address;

            unsafe
            {
                address = (IntPtr)(hGCache.GetPointer() + offset);
            }

            int readCount = await ReadCharsAsync(
                textReader,
                address,
                hGCache.Count - offset);

            offset += readCount;

            if (offset == hGCache.Count)
            {
                goto Loop;
            }

            return(offset);
        }
        public static unsafe int Buffer(this HGlobalCache <char> hGCache, TextReader textReader)
        {
            int offset = 0;

Loop:

            if (offset >= hGCache.Count)
            {
                hGCache.Expand(1218);
            }

            int readCount = ReadChars(
                textReader,
                hGCache.GetPointer() + offset,
                hGCache.Count - offset);

            offset += readCount;

            if (offset == hGCache.Count)
            {
                goto Loop;
            }

            return(offset);
        }
Exemple #3
0
        private bool TryReadParsedOfStr <T>(out T value)
        {
            value = default;

            var strBytesLength = TryReadStringHead();

            if (strBytesLength > 0)
            {
                ReadStringToHGlobal(strBytesLength);

                if (typeof(T) == typeof(DateTime) && DateTimeHelper.TryParseISODateTime(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, DateTime>(ref value)))
                {
                    return(true);
                }

                if (typeof(T) == typeof(DateTimeOffset) && DateTimeHelper.TryParseISODateTime(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, DateTimeOffset>(ref value)))
                {
                    return(true);
                }

                if (typeof(T) == typeof(Guid) && NumberHelper.TryParse(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, Guid>(ref value)) == hGlobal.Count)
                {
                    return(true);
                }

                if (typeof(T) == typeof(decimal))
                {
                    var num = NumberHelper.TryParse(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, decimal>(ref value));

                    if (num != hGlobal.Count)
                    {
                        var numberInfo = NumberHelper.GetNumberInfo(hGlobal.GetPointer(), hGlobal.Count, 10);

                        if (numberInfo.IsNumber)
                        {
                            Unsafe.As <T, decimal>(ref value) = numberInfo.ToDecimal();

                            num = numberInfo.End;
                        }
                    }

                    if (num == hGlobal.Count)
                    {
                        return(true);
                    }
                }

                if (typeof(T) == typeof(double))
                {
                    var num = NumberHelper.Decimal.TryParse(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, double>(ref value));

                    if (num != hGlobal.Count)
                    {
                        var numberInfo = NumberHelper.GetNumberInfo(hGlobal.GetPointer(), hGlobal.Count, 10);

                        if (numberInfo.IsNumber)
                        {
                            Unsafe.As <T, double>(ref value) = numberInfo.ToDouble();

                            num = numberInfo.End;
                        }
                    }

                    if (num == hGlobal.Count)
                    {
                        return(true);
                    }
                }

                if (typeof(T) == typeof(long))
                {
                    var num = NumberHelper.Decimal.TryParse(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, long>(ref value));

                    if (num != hGlobal.Count)
                    {
                        var numberInfo = NumberHelper.GetNumberInfo(hGlobal.GetPointer(), hGlobal.Count, 10);

                        if (numberInfo.IsNumber)
                        {
                            Unsafe.As <T, long>(ref value) = numberInfo.ToInt64();

                            num = numberInfo.End;
                        }
                    }

                    if (num == hGlobal.Count)
                    {
                        return(true);
                    }
                }

                if (typeof(T) == typeof(ulong))
                {
                    var num = NumberHelper.Decimal.TryParse(hGlobal.GetPointer(), hGlobal.Count, out Unsafe.As <T, ulong>(ref value));

                    if (num != hGlobal.Count)
                    {
                        var numberInfo = NumberHelper.GetNumberInfo(hGlobal.GetPointer(), hGlobal.Count, 10);

                        if (numberInfo.IsNumber)
                        {
                            Unsafe.As <T, ulong>(ref value) = numberInfo.ToUInt64();

                            num = numberInfo.End;
                        }
                    }

                    if (num == hGlobal.Count)
                    {
                        return(true);
                    }
                }

                var str = new string(hGlobal.GetPointer(), 0, hGlobal.Count);

                if (typeof(T) == typeof(DateTime))
                {
                    Unsafe.As <T, DateTime>(ref value) = DateTime.Parse(str);

                    return(true);
                }

                if (typeof(T) == typeof(DateTimeOffset))
                {
                    Unsafe.As <T, DateTimeOffset>(ref value) = DateTimeOffset.Parse(str);

                    return(true);
                }

                if (typeof(T) == typeof(Guid))
                {
                    Unsafe.As <T, Guid>(ref value) = new Guid(str);

                    return(true);
                }

                if (typeof(T) == typeof(decimal))
                {
                    Unsafe.As <T, decimal>(ref value) = decimal.Parse(str);

                    return(true);
                }

                if (typeof(T) == typeof(double))
                {
                    Unsafe.As <T, double>(ref value) = double.Parse(str);

                    return(true);
                }

                if (typeof(T) == typeof(long))
                {
                    Unsafe.As <T, long>(ref value) = long.Parse(str);

                    return(true);
                }

                if (typeof(T) == typeof(ulong))
                {
                    Unsafe.As <T, ulong>(ref value) = ulong.Parse(str);

                    return(true);
                }

                //value = XConvert<T>.Convert(str);

                //return true;
            }

            return(false);
        }
        public void Append(byte value)
        {
            HGCache.GetPointer()[offset] = value;

            ++offset;
        }