当前位置: 首页>>代码示例>>C#>>正文


C# Formatting.FormattingData类代码示例

本文整理汇总了C#中System.Text.Formatting.FormattingData的典型用法代码示例。如果您正苦于以下问题:C# FormattingData类的具体用法?C# FormattingData怎么用?C# FormattingData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FormattingData类属于System.Text.Formatting命名空间,在下文中一共展示了FormattingData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryFormatInt64

        // TODO: format should be ReadOnlySpan<char>
        internal static bool TryFormatInt64(long value, byte numberOfBytes, Span<byte> buffer, Span<char> format, FormattingData formattingData, out int bytesWritten)
        {
            Precondition.Require(numberOfBytes <= sizeof(long));

            Format.Parsed parsedFormat = Format.Parse(format);
            return TryFormatInt64(value, numberOfBytes, buffer, parsedFormat, formattingData, out bytesWritten);
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:8,代码来源:IntegerFormatter.cs

示例2: CustomCultureTests

        // Sets up cultures with digits represented by 1 or 5 'A's (0) through 1 or 5 'J's (9) and the minus sigh represented by an underscore followed by a question mark
        static CustomCultureTests()
        {
            byte[][] utf16digitsAndSymbols = new byte[17][];
            for (ushort digit = 0; digit < 10; digit++)
            {
                char digitChar = (char)(digit + 'A');
                var digitString = new string(digitChar, 5);
                utf16digitsAndSymbols[digit] = GetBytesUtf16(digitString);
            }
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.DecimalSeparator] = GetBytesUtf16(".");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.GroupSeparator] = GetBytesUtf16(",");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.MinusSign] = GetBytesUtf16("_?");
            Culture5 = new FormattingData(utf16digitsAndSymbols, FormattingData.Encoding.Utf16);

            utf16digitsAndSymbols = new byte[17][];
            for (ushort digit = 0; digit < 10; digit++)
            {
                char digitChar = (char)(digit + 'A');
                var digitString = new string(digitChar, 1);
                utf16digitsAndSymbols[digit] = GetBytesUtf16(digitString);
            }
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.DecimalSeparator] = GetBytesUtf16(".");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.GroupSeparator] = GetBytesUtf16(",");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.MinusSign] = GetBytesUtf16("_?");
            Culture1 = new FormattingData(utf16digitsAndSymbols, FormattingData.Encoding.Utf16);
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:27,代码来源:CustomCulture.cs

示例3: TryFormatUInt64

        internal static bool TryFormatUInt64(ulong value, byte numberOfBytes, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if(format.Symbol == 'g')
            {
                format.Symbol = 'G';
            }

            if (format.IsHexadecimal && formattingData.IsUtf16) {
                return TryFormatHexadecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten);
            }

            if (format.IsHexadecimal && formattingData.IsUtf8) {
                return TryFormatHexadecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten);
            }

            if ((formattingData.IsInvariantUtf16) && (format.Symbol == 'D' || format.Symbol == 'G')) {
                return TryFormatDecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten);
            }

            if ((formattingData.IsInvariantUtf8) && (format.Symbol == 'D' || format.Symbol == 'G')) {
                return TryFormatDecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten);
            }

            return TryFormatDecimal(value, buffer, format, formattingData, out bytesWritten);     
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:25,代码来源:IntegerFormatter.cs

示例4: TryFormat

        public static bool TryFormat(this DateTime value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (format.IsDefault)
            {
                format.Symbol = 'G';
            }
            Precondition.Require(format.Symbol == 'R' || format.Symbol == 'O' || format.Symbol == 'G');

            switch (format.Symbol)
            {
                case 'R':
                    var utc = value.ToUniversalTime();
                    if (formattingData.IsUtf16)
                    {
                        return TryFormatDateTimeRfc1123(utc, buffer, FormattingData.InvariantUtf16, out bytesWritten);
                    }
                    else
                    {
                        return TryFormatDateTimeRfc1123(utc, buffer, FormattingData.InvariantUtf8, out bytesWritten);
                    }
                case 'O':
                    if (formattingData.IsUtf16)
                    {
                        return TryFormatDateTimeFormatO(value, true, buffer, FormattingData.InvariantUtf16, out bytesWritten);
                    }
                    else
                    {
                        return TryFormatDateTimeFormatO(value, true, buffer, FormattingData.InvariantUtf8, out bytesWritten);
                    }
                case 'G':
                    return TryFormatDateTimeFormagG(value, buffer, formattingData, out bytesWritten);
                default:
                    throw new NotImplementedException();
            }
        }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:35,代码来源:PrimitiveFormatters_time.cs

示例5: JsonWriter

 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8);
 }
开发者ID:axxu,项目名称:corefxlab,代码行数:7,代码来源:JsonWriter.cs

示例6: JsonWriter

 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _pool = new ManagedBufferPool<byte>(2048);
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8, _pool);
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:8,代码来源:JsonWriter.cs

示例7: TryFormat

 public static bool TryFormat(this float value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
 {
     if (format.IsDefault)
     {
         format.Symbol = 'G';
     }
     Precondition.Require(format.Symbol == 'G');
     return FloatFormatter.TryFormatNumber(value, true, buffer, format, formattingData, out bytesWritten);
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormatters_float.cs

示例8: MultispanFormatter

 public MultispanFormatter(Multispan<byte> buffer, int segmentSize, FormattingData formattingData)
 {
     _formattingData = formattingData;
     _segmentSize = segmentSize;
     _buffer = buffer;
     int index = _buffer.AppendNewSegment(_segmentSize); // TODO: is this the right thing to do? Should Multispan be resilient to empty segment list?
     _lastFull = _buffer.Last;
     _buffer.ResizeSegment(index, 0);
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:9,代码来源:MultispanFormatter.cs

示例9: TryParse

        public static bool TryParse(ReadOnlySpan<byte> text, FormattingData.Encoding encoding, out uint value, out int bytesConsumed)
        {
            Precondition.Require(text.Length > 0);
            Precondition.Require(encoding == FormattingData.Encoding.Utf8 || text.Length > 1);

            value = 0;
            bytesConsumed = 0;

            if (text[0] == '0')
            {
                if (encoding == FormattingData.Encoding.Utf16)
                {
                    bytesConsumed = 2;
                    return text[1] == 0;
                }
                bytesConsumed = 1;
                return true;
            }

            for (int byteIndex = 0; byteIndex < text.Length; byteIndex++)
            {
                byte nextByte = text[byteIndex];
                if (nextByte < '0' || nextByte > '9')
                {
                    if (bytesConsumed == 0)
                    {
                        value = default(uint);
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                uint candidate = value * 10;
                candidate += (uint)nextByte - '0';
                if (candidate > value)
                {
                    value = candidate;
                }
                else {
                    return true;
                }
                bytesConsumed++;
                if (encoding == FormattingData.Encoding.Utf16)
                {
                    byteIndex++;
                    if (byteIndex >= text.Length || text[byteIndex] != 0)
                    {
                        return false;
                    }
                    bytesConsumed++;
                }
            }

            return true;
        }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:56,代码来源:InvariantParser_uint.cs

示例10: StreamFormatter

 public StreamFormatter(Stream stream, FormattingData formattingData, int bufferSize = 256)
 {
     _buffer = null;
     if (bufferSize > 0)
     {
         _buffer = BufferPool.Shared.RentBuffer(bufferSize);
     }
     _formattingData = formattingData;
     _stream = stream;
 }
开发者ID:ReedKimble,项目名称:corefxlab,代码行数:10,代码来源:StreamFormatter.cs

示例11: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, BufferPool pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = BufferPool.Shared;
     }
     _buffer = _pool.RentBuffer(capacity);
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs

示例12: StreamFormatter

 public StreamFormatter(Stream stream, FormattingData formattingData, ManagedBufferPool<byte> pool, int bufferSize = 256)
 {
     _pool = pool;
     _buffer = null;
     if (bufferSize > 0)
     {
         _buffer = _pool.RentBuffer(bufferSize);
     }
     _formattingData = formattingData;
     _stream = stream;
 }
开发者ID:kronic,项目名称:corefxlab,代码行数:11,代码来源:StreamFormatter.cs

示例13: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, ArrayPool<byte> pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = ArrayPool<byte>.Shared;
     }
     _buffer = _pool.Rent(capacity);
 }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs

示例14: TryFormat

        public bool TryFormat(Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (!PrimitiveFormatters.TryFormat(_age, buffer, format, formattingData, out bytesWritten)) return false;

            char symbol = _inMonths ? 'm' : 'y';
            int symbolBytes;
            if (!PrimitiveFormatters.TryFormat(symbol, buffer.Slice(bytesWritten), format, formattingData, out symbolBytes)) return false;

            bytesWritten += symbolBytes;
            return true;
        }
开发者ID:ReedKimble,项目名称:corefxlab,代码行数:11,代码来源:CustomTypeFormatting.cs

示例15: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, ManagedBufferPool<byte> pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = new ManagedBufferPool<byte>(capacity);
     }
     _buffer = _pool.RentBuffer(capacity);
 }
开发者ID:kronic,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs


注:本文中的System.Text.Formatting.FormattingData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。