本文整理汇总了C#中Span类的典型用法代码示例。如果您正苦于以下问题:C# Span类的具体用法?C# Span怎么用?C# Span使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Span类属于命名空间,在下文中一共展示了Span类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Parse
// TODO: format should be ReadOnlySpan<T>
public static Format.Parsed Parse(Span<char> format)
{
if (format.Length == 0)
{
return default(Format.Parsed);
}
uint precision = NoPrecision;
if (format.Length > 1)
{
var span = format.Slice(1, format.Length - 1);
if (!InvariantParser.TryParse(span, out precision))
{
throw new NotImplementedException("UnableToParsePrecision");
}
if (precision > Parsed.MaxPrecision)
{
// TODO: this is a contract violation
throw new Exception("PrecisionValueOutOfRange");
}
}
// TODO: this is duplicated from above. It needs to be refactored
var specifier = format[0];
return new Parsed(specifier, (byte)precision);
}
开发者ID:tarekgh,项目名称:corefxlab,代码行数:29,代码来源:ParsedFormat.cs
示例17: TryDecodeCodePoint
public static bool TryDecodeCodePoint(Span<byte> buffer, out UnicodeCodePoint codePoint, out int encodedBytes)
{
if (buffer.Length == 0)
{
codePoint = default(UnicodeCodePoint);
encodedBytes = default(int);
return false;
}
byte first = buffer[0];
if (!TryGetFirstByteCodePointValue(first, out codePoint, out encodedBytes))
return false;
if (buffer.Length < encodedBytes)
return false;
// TODO: Should we manually inline this for values 1-4 or will compiler do this for us?
for (int i = 1; i < encodedBytes; i++)
{
if (!TryReadCodePointByte(buffer[i], ref codePoint))
return false;
}
return true;
}
开发者ID:hanin,项目名称:corefxlab,代码行数:25,代码来源:Utf8Encoder.cs
示例18: TestCreateOverArray
public bool TestCreateOverArray(Tester t)
{
for (int i = 0; i < 2; i++) {
var ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// Try out two ways of creating a slice:
Span<int> slice;
if (i == 0) {
slice = new Span<int>(ints);
}
else {
slice = ints.Slice();
}
t.AssertEqual(ints.Length, slice.Length);
t.AssertEqual(0, 1);
// Now try out two ways of walking the slice's contents:
for (int j = 0; j < ints.Length; j++) {
t.AssertEqual(ints[j], slice[j]);
}
{
int j = 0;
foreach (var x in slice) {
t.AssertEqual(ints[j], x);
j++;
}
}
}
return true;
}
开发者ID:IDisposable,项目名称:corefxlab,代码行数:29,代码来源:Tests.cs
示例19: TryRewrite
internal static bool TryRewrite(DbQueryCommandTree tree, Span span, MergeOption mergeOption, AliasGenerator aliasGenerator, out DbExpression newQuery, out SpanIndex spanInfo)
{
newQuery = null;
spanInfo = null;
ObjectSpanRewriter rewriter = null;
bool requiresRelationshipSpan = Span.RequiresRelationshipSpan(mergeOption);
// Potentially perform a rewrite for span.
// Note that the public 'Span' property is NOT used to retrieve the Span instance
// since this forces creation of a Span object that may not be required.
if (span != null && span.SpanList.Count > 0)
{
rewriter = new ObjectFullSpanRewriter(tree, tree.Query, span, aliasGenerator);
}
else if (requiresRelationshipSpan)
{
rewriter = new ObjectSpanRewriter(tree, tree.Query, aliasGenerator);
}
if (rewriter != null)
{
rewriter.RelationshipSpan = requiresRelationshipSpan;
newQuery = rewriter.RewriteQuery();
if (newQuery != null)
{
Debug.Assert(rewriter.SpanIndex != null || tree.Query.ResultType.EdmEquals(newQuery.ResultType), "Query was rewritten for Span but no SpanIndex was created?");
spanInfo = rewriter.SpanIndex;
}
}
return (spanInfo != null);
}
开发者ID:uQr,项目名称:referencesource,代码行数:33,代码来源:ObjectSpanRewriter.cs
示例20: Append
//TODO: this should use Span<byte>
public void Append(Span<char> substring)
{
for (int i = 0; i < substring.Length; i++)
{
Append(substring[i]);
}
}
开发者ID:ReedKimble,项目名称:corefxlab,代码行数:8,代码来源:StringFormatter.cs
注:本文中的Span类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论