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


C# StringSegment类代码示例

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


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

示例1: FormatFilter_ContextContainsFormat_DefaultFormat

        public void FormatFilter_ContextContainsFormat_DefaultFormat(
            string format,
            FormatSource place,
            string contentType)
        {
            // Arrange
            var mediaType = new StringSegment("application/json");
            var mockObjects = new MockObjects(format, place);

            var resultExecutingContext = mockObjects.CreateResultExecutingContext();
            var resourceExecutingContext = mockObjects.CreateResourceExecutingContext(new IFilterMetadata[] { });

            var filter = new FormatFilter(mockObjects.OptionsManager);

            // Act
            filter.OnResourceExecuting(resourceExecutingContext);

            // Assert
            Assert.Null(resourceExecutingContext.Result);

            // Act
            filter.OnResultExecuting(resultExecutingContext);

            // Assert
            var objectResult = Assert.IsType<ObjectResult>(resultExecutingContext.Result);
            Assert.Equal(1, objectResult.ContentTypes.Count);
            MediaTypeAssert.Equal(mediaType, objectResult.ContentTypes[0]);
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:28,代码来源:FormatFilterTest.cs

示例2: StringSource

 /// <summary>
 /// Initializes a new instance of the <see cref="StringSource"/> structure.
 /// </summary>
 /// <param name="segment">The <see cref="StringSegment"/> that contains the string data.</param>
 public StringSource(StringSegment segment)
 {
     this.str     = segment.SourceString;
     this.builder = segment.SourceStringBuilder;
     this.Start   = segment.Start;
     this.Length  = segment.Length;
 }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:11,代码来源:StringSource.cs

示例3: Null

 public void Null()
 {
     var segment = new StringSegment(null);
     Assert.Equal(0, segment.Length);
     Assert.True(segment.IsEmpty);
     Assert.True(segment.IsNull);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:7,代码来源:StringSegmentFacts.cs

示例4: Empty

 public void Empty()
 {
     var segment = new StringSegment("");
     Assert.Equal(0, segment.Length);
     Assert.True(segment.IsEmpty);
     Assert.False(segment.IsNull);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:7,代码来源:StringSegmentFacts.cs

示例5: StringSegment_IndexOfString_ReturnsNegativeOneForNonExistingCharacter

        public void StringSegment_IndexOfString_ReturnsNegativeOneForNonExistingCharacter()
        {
            var segment = new StringSegment("Hello, world!");
            var result = segment.IndexOf("zorld");

            TheResultingValue(result).ShouldBe(-1);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:StringSegmentTest.cs

示例6: StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter

        public void StringSegment_IndexOfString_ReturnsCorrectValueForExistingCharacter()
        {
            var segment = new StringSegment("Hello, world!");
            var result = segment.IndexOf("world");

            TheResultingValue(result).ShouldBe(7);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:StringSegmentTest.cs

示例7: TryParseHexadecimalInt32

        /// <summary>
        /// Converts the hexadecimal text of the specified <see cref="StringSegment"/> to an 
        /// instance of <see cref="Int32"/> if possible.
        /// </summary>
        /// <param name="segment">The string segment to convert.</param>
        /// <param name="result">The converted value.</param>
        /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns>
        public static Boolean TryParseHexadecimalInt32(StringSegment segment, out Int32 result)
        {
            var spaceCountLeading = CountLeadingSpace(ref segment);
            var spaceCountTrailing = CountTrailingSpace(ref segment);

            var valueStart = spaceCountLeading;
            var valueLength = segment.Length - (spaceCountLeading + spaceCountTrailing);

            var magnitude = (Int64)Math.Pow(16, valueLength - 1);
            var digit = 0;
            var total = 0L;
            for (int i = 0; i < valueLength; i++)
            {
                if (!ConvertHexadecimalDigit(segment[valueStart + i], out digit))
                {
                    result = 0;
                    return false;
                }

                total += (magnitude * digit);
                magnitude /= 16;
            }

            if (total > Int32.MaxValue)
                throw new OverflowException();

            result = (Int32)total;
            return true;
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:36,代码来源:StringSegmentConversion.cs

示例8: CharReaderShouldReadToCharacter

 public void CharReaderShouldReadToCharacter()
 {
     StringSegment source = new StringSegment("abc:123");
     CharReader reader = new CharReader(source);
     reader.ReadTo(':', false);
     Assert.Equal(3, reader.Position);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:7,代码来源:CharReaderFacts.cs

示例9: CharReaderFromSegment

 public void CharReaderFromSegment()
 {
     var segment = new StringSegment(TestContent);
     var reader = new CharReader(segment);
     Assert.False(reader.IsDone);
     Assert.Equal(-1, reader.Position);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:7,代码来源:CharReaderFacts.cs

示例10: DefaultConstructor

        public void DefaultConstructor()
        {
            var segment = new StringSegment();
            Assert.Equal(0, segment.Length);

            Assert.True(segment.IsEmpty);
            Assert.True(segment.IsNull);
        }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:8,代码来源:StringSegmentFacts.cs

示例11: StringSegment_CanBeCreatedFromString

        public void StringSegment_CanBeCreatedFromString()
        {
            var source = "Hello, world!";
            var segment = new StringSegment(source, 2, 4);

            TheResultingString(segment.ToString())
                .ShouldBe("llo,");
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:8,代码来源:StringSegmentTest.cs

示例12: TextParserToken

 /// <summary>
 /// Initializes a new instance of the <see cref="TextParserToken"/> structure.
 /// </summary>
 /// <param name="tokenType">The token's type.</param>
 /// <param name="text">The token's text.</param>
 /// <param name="sourceOffset">The offset of the first character in the source text that produced this token.</param>
 /// <param name="sourceLength">The number of characters in the source text that produced this token.</param>
 /// <param name="isNonBreakingSpace">A value indicating whether this token represents a non-breaking space.</param>
 internal TextParserToken(TextParserTokenType tokenType, StringSegment text, Int32 sourceOffset, Int32 sourceLength, Boolean isNonBreakingSpace = false)
 {
     this.tokenType = tokenType;
     this.text = text;
     this.sourceOffset = sourceOffset;
     this.sourceLength = sourceLength;
     this.isNonBreakingSpace = isNonBreakingSpace;
 }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:16,代码来源:TextParserToken.cs

示例13: StringFormatterCommandInfo

 /// <summary>
 /// Initializes a new instance of the <see cref="StringFormatterCommandInfo"/> structure.
 /// </summary>
 /// <param name="commandName">The name of the command being handled.</param>
 /// <param name="commandArgs">The command's argument list.</param>
 /// <param name="commandHandler">The command's handler.</param>
 public StringFormatterCommandInfo(StringSegment commandName, 
     StringFormatterCommandArguments commandArgs,
     StringFormatterCommandHandler commandHandler)
 {
     this.CommandName = commandName;
     this.CommandArguments = commandArgs;
     this.CommandHandler = commandHandler;
 }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:14,代码来源:StringFormatterCommandInfo.cs

示例14: NoRunFactories

 public void NoRunFactories()
 {
     WikiRunParser parser = new WikiRunParser(Enumerable.Empty<WikiRunFactory>());
     StringSegment text = new StringSegment("we're");
     List<WikiRun> runs = parser.Parse(text).ToList();
     Assert.AreEqual(1, runs.Count);
     Assert.AreEqual("we're", ((TextWikiRun) runs[0]).Text);
 }
开发者ID:ejball,项目名称:EdgeWiki,代码行数:8,代码来源:WikiRunParserTests.cs

示例15: ParseUInt32

        public static UInt32 ParseUInt32(StringSegment segment)
        {
            UInt32 value;
            if (!TryParseUInt32(segment, out value))
                throw new FormatException();

            return value;
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:8,代码来源:StringSegmentConversion.cs


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