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


C# Span类代码示例

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


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

示例1: BufferReaderRead

        public void BufferReaderRead()
        {
            Assert.True(BitConverter.IsLittleEndian);

            ulong value = 0x8877665544332211; // [11 22 33 44 55 66 77 88]
            Span<byte> span;
            unsafe {
                span = new Span<byte>(&value, 8);
            }

            Assert.Equal<byte>(0x11, span.ReadBigEndian<byte>());
            Assert.Equal<byte>(0x11, span.ReadLittleEndian<byte>());
            Assert.Equal<sbyte>(0x11, span.ReadBigEndian<sbyte>());
            Assert.Equal<sbyte>(0x11, span.ReadLittleEndian<sbyte>());

            Assert.Equal<ushort>(0x1122, span.ReadBigEndian<ushort>());
            Assert.Equal<ushort>(0x2211, span.ReadLittleEndian<ushort>());
            Assert.Equal<short>(0x1122, span.ReadBigEndian<short>());
            Assert.Equal<short>(0x2211, span.ReadLittleEndian<short>());

            Assert.Equal<uint>(0x11223344, span.ReadBigEndian<uint>());
            Assert.Equal<uint>(0x44332211, span.ReadLittleEndian<uint>());
            Assert.Equal<int>(0x11223344, span.ReadBigEndian<int>());
            Assert.Equal<int>(0x44332211, span.ReadLittleEndian<int>());

            Assert.Equal<ulong>(0x1122334455667788, span.ReadBigEndian<ulong>());
            Assert.Equal<ulong>(0x8877665544332211, span.ReadLittleEndian<ulong>());
            Assert.Equal<long>(0x1122334455667788, span.ReadBigEndian<long>());
            Assert.Equal<long>(unchecked((long)0x8877665544332211), span.ReadLittleEndian<long>());

        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:31,代码来源:BufferReaderTests.cs

示例2: FindTabSpan

        private static Span FindTabSpan(Span zenSpan, bool isReverse, string text, Regex regex)
        {
            MatchCollection matches = regex.Matches(text);

            if (!isReverse)
            {
                foreach (Match match in matches)
                {
                    Group group = match.Groups[2];

                    if (group.Index >= zenSpan.Start)
                    {
                        return new Span(group.Index, group.Length);
                    }
                }
            }
            else
            {
                for (int i = matches.Count - 1; i >= 0; i--)
                {
                    Group group = matches[i].Groups[2];

                    if (group.Index < zenSpan.End)
                    {
                        return new Span(group.Index, group.Length);
                    }
                }
            }

            return new Span();
        }
开发者ID:nelsonad,项目名称:WebEssentials2013,代码行数:31,代码来源:ZenCodingCommandTarget.cs

示例3: EditingTests

 public EditingTests()
 {
     m_promptSpan = new Span( m_prompt );
      m_promptWrapSpan = new Span( m_promptWrap );
      m_promptOutputSpan = new Span( m_promptOutput );
      m_promptOutputWrapSpan = new Span( m_promptOutputWrap );
 }
开发者ID:andrevdm,项目名称:CSharpConsoleControl,代码行数:7,代码来源:EditingTests.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: Encode

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <returns>Number of bytes written to the destination.</returns>
        public static int Encode(ReadOnlySpan<byte> source, Span<byte> destination)
        {
            int di = 0;
            int si = 0;
            byte b0, b1, b2, b3;
            for (; si<source.Length - 2;) {
                var result = Encode(source.Slice(si));
                si += 3;
                destination.Slice(di).Write(result);
                di += 4;
            }

            if (si == source.Length - 1) {
                Encode(source[si], 0, 0, out b0, out b1, out b2, out b3);
                destination[di++] = b0;
                destination[di++] = b1;
                destination[di++] = s_encodingMap[64];
                destination[di++] = s_encodingMap[64];
            }
            else if(si == source.Length - 2) {
                Encode(source[si++], source[si], 0, out b0, out b1, out b2, out b3);
                destination[di++] = b0;
                destination[di++] = b1;
                destination[di++] = b2;
                destination[di++] = s_encodingMap[64];
            }

            return di; 
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:35,代码来源:Base64.cs

示例6: ParseSpanAnnotation

        public static BratAnnotation ParseSpanAnnotation(Span[] tokens, string line) {
            if (tokens.Length > 4) {
                string type = tokens[TYPE_OFFSET].GetCoveredText(line);

                int endOffset = -1;

                int firstTextTokenIndex = -1;

                for (int i = END_OFFSET; i < tokens.Length; i++) {
                    if (!tokens[i].GetCoveredText(line).Contains(";")) {

                        endOffset = ParseInt(tokens[i].GetCoveredText(line));
                        firstTextTokenIndex = i + 1;
                        break;
                    }
                }

                var id = tokens[ID_OFFSET].GetCoveredText(line);

                var coveredText = line.Substring(tokens[firstTextTokenIndex].Start, tokens[endOffset].End);

                return new SpanAnnotation(
                    id, 
                    type,
                    new Span(ParseInt(tokens[BEGIN_OFFSET].GetCoveredText(line)), endOffset, type), 
                    coveredText);

            }
            throw new InvalidFormatException("Line must have at least 5 fields.");
        }
开发者ID:knuppe,项目名称:SharpNL,代码行数:30,代码来源:BratParser.cs

示例7: WriteOutputTests

 public WriteOutputTests()
 {
     m_promptSpan = new Span( m_prompt );
      m_promptWrapSpan = new Span( m_promptWrap );
      m_promptOutputSpan = new Span( m_promptOutput );
      m_promptOutputWrapSpan = new Span( m_promptOutputWrap );
 }
开发者ID:andrevdm,项目名称:CSharpConsoleControl,代码行数:7,代码来源:WriteOutputTests.cs

示例8: Intersection

        /// <summary>
        ///     Provides the intersection of two spans
        /// </summary>
        /// <param name="span1"></param>
        /// <param name="span2"></param>
        /// <returns></returns>
        public static Span Intersection(Span span1, Span span2)
        {
            Span retVal;

            if (span1.LowBound > span2.LowBound)
            {
                Span tmp = span1;
                span1 = span2;
                span2 = tmp;
            }
            // span1.LowBound <= span2.LowBound

            if (span1.HighBound < span2.LowBound)
            {
                retVal = null;
            }
            else
            {
                // span1.LowBound < span2.LowBound and span1.HighBound >= span2.LowBound
                int lowBound = span2.LowBound;
                int highBound;
                if (span1.HighBound > span2.HighBound)
                {
                    highBound = span2.HighBound;
                }
                else
                {
                    highBound = span1.HighBound;
                }

                retVal = new Span(lowBound, highBound);
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:41,代码来源:Span.cs

示例9: DisplayRecognitionError

        public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
        {
            var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense);
            if (outputWindow != null)
            {
                string header = GetErrorHeader(e);
                string message = GetErrorMessage(e, tokenNames);
                Span span = new Span();
                if (e.Token != null)
                    span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1);

                if (message.Length > 100)
                    message = message.Substring(0, 100) + " ...";

                ITextDocument document;
                if (TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document) && document != null)
                {
                    string fileName = document.FilePath;
                    var line = Snapshot.GetLineFromPosition(span.Start);
                    message = string.Format("{0}({1},{2}): {3}: {4}", fileName, line.LineNumber + 1, span.Start - line.Start.Position + 1, GetType().Name, message);
                }

                outputWindow.WriteLine(message);
            }

            base.DisplayRecognitionError(tokenNames, e);
        }
开发者ID:sebandraos,项目名称:LangSvcV2,代码行数:27,代码来源:AlloyBaseWalker.g3.cs

示例10: SparkTagParameter

 public SparkTagParameter(string documentation, Span span, string name, ISignature signature)
 {
     Documentation = documentation;
     Locus = span;
     Name = name;
     Signature = signature;
 }
开发者ID:aloker,项目名称:spark,代码行数:7,代码来源:SparkTagParameter.cs

示例11: Classify

        private static List<Tuple<string, string>> Classify(string markdown, Span? subSpan = null)
        {
            if (subSpan == null)
            {
                var spanStart = markdown.IndexOf("(<");
                if (spanStart >= 0)
                {
                    markdown = markdown.Remove(spanStart, 2);
                    var spanEnd = markdown.IndexOf(">)", spanStart);
                    if (spanEnd < 0)
                        throw new ArgumentException("Markdown (<...>) span indicator must be well-formed", "markdown");
                    markdown = markdown.Remove(spanEnd, 2);
                    subSpan = Span.FromBounds(spanStart, spanEnd);
                }
            }

            var crlf = newline.Replace(markdown, "\r\n");
            var lf = newline.Replace(markdown, "\n");
            var cr = newline.Replace(markdown, "\r");

            // Test newline equivalence on the full source
            // string.  We cannot pass the subspan because
            // newline replacements will move its indices.
            // Also, this part is only to test the parser,
            // which doesn't get subspans anyway.
            var fullResult = RunParseCase(crlf);
            RunParseCase(lf).Should().Equal(fullResult, "LF should be the same as CRLF");
            RunParseCase(cr).Should().Equal(fullResult, "CR should be the same as CRLF");

            return RunParseCase(markdown, subSpan);
        }
开发者ID:EdsonF,项目名称:WebEssentials2013,代码行数:31,代码来源:MarkdownClassifierTests.cs

示例12: InvokeZenCoding

        private bool InvokeZenCoding()
        {
            Span zenSpan = GetText();

            if (zenSpan.Length == 0 || TextView.Selection.SelectedSpans[0].Length > 0 || !IsValidTextBuffer())
                return false;

            string zenSyntax = TextView.TextBuffer.CurrentSnapshot.GetText(zenSpan);

            Parser parser = new Parser();
            string result = parser.Parse(zenSyntax, ZenType.HTML);

            if (!string.IsNullOrEmpty(result))
            {
                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                {
                    using (EditorExtensionsPackage.UndoContext("ZenCoding"))
                    {
                        ITextSelection selection = UpdateTextBuffer(zenSpan, result);

                        EditorExtensionsPackage.ExecuteCommand("Edit.FormatSelection");

                        Span newSpan = new Span(zenSpan.Start, selection.SelectedSpans[0].Length);
                        selection.Clear();
                        SetCaret(newSpan, false);
                    }
                }), DispatcherPriority.ApplicationIdle, null);

                return true;
            }

            return false;
        }
开发者ID:NickCraver,项目名称:WebEssentials2013,代码行数:33,代码来源:ZenCodingCommandTarget.cs

示例13: StartServerTrace

 public void StartServerTrace()
 {
     if (isTraceOn)
     {
         serverSpan = StartTrace(spanTracer.ReceiveServerSpan);
     }
 }
开发者ID:theburningmonk,项目名称:Medidata.ZipkinTracerModule,代码行数:7,代码来源:ZipkinClient.cs

示例14: StartClientTrace

 public void StartClientTrace()
 {
     if (isTraceOn)
     {
         clientSpan = StartTrace(spanTracer.SendClientSpan);
     }
 }
开发者ID:theburningmonk,项目名称:Medidata.ZipkinTracerModule,代码行数:7,代码来源:ZipkinClient.cs

示例15: ByteSpanEqualsTestsTwoDifferentInstancesOfBuffersWithOneValueDifferent

        public unsafe void ByteSpanEqualsTestsTwoDifferentInstancesOfBuffersWithOneValueDifferent()
        {
            const int bufferLength = 128;
            byte[] buffer1 = new byte[bufferLength];
            byte[] buffer2 = new byte[bufferLength];

            for (int i = 0; i < bufferLength; i++)
            {
                buffer1[i] = (byte)(bufferLength + 1 - i);
                buffer2[i] = (byte)(bufferLength + 1 - i);
            }

            fixed (byte* buffer1pinned = buffer1)
            fixed (byte* buffer2pinned = buffer2)
            {
                Span<byte> b1 = new Span<byte>(buffer1pinned, bufferLength);
                Span<byte> b2 = new Span<byte>(buffer2pinned, bufferLength);

                for (int i = 0; i < bufferLength; i++)
                {
                    for (int diffPosition = i; diffPosition < bufferLength; diffPosition++)
                    {
                        buffer1[diffPosition] = unchecked((byte)(buffer1[diffPosition] + 1));
                        Assert.False(b1.Slice(i).SequenceEqual(b2.Slice(i)));
                    }
                }
            }
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:28,代码来源:BasicUnitTests.cs


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