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


C# MessagePackObject.AsString方法代码示例

本文整理汇总了C#中MessagePackObject.AsString方法的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject.AsString方法的具体用法?C# MessagePackObject.AsString怎么用?C# MessagePackObject.AsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessagePackObject的用法示例。


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

示例1: TestAsString1_EncodingIsNotUtf32_SpecifyUtf32_Fail

		public void TestAsString1_EncodingIsNotUtf32_SpecifyUtf32_Fail()
		{
#if MONO
			Assert.Inconclusive( "UTF32Encoding does not throw exception on Mono FCL." );
#endif
			var target = new MessagePackObject( new byte[] { 0xFF } );
			Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF32Encoding( bigEndian: false, byteOrderMark: false, throwOnInvalidCharacters: true ) ) );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:8,代码来源:MessagePackObjectTest.Strings.cs

示例2: TestAsString1_EncodingIsUtf32_SpecifyUtf32_Success

		public void TestAsString1_EncodingIsUtf32_SpecifyUtf32_Success()
		{
			var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
			var result = target.AsString( Encoding.UTF32 );
			Assert.AreEqual( _japanese, result );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:6,代码来源:MessagePackObjectTest.Strings.cs

示例3: TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail

		public void TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail()
		{
			var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
			Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) ) );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例4: TestAsString1_EncodingMissmatchAndReturnsNull_Null

		public void TestAsString1_EncodingMissmatchAndReturnsNull_Null()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			Assert.Throws<InvalidOperationException>( () => target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false ) ) );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例5: TestAsString1_EncodingIsNull

		public void TestAsString1_EncodingIsNull()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			Assert.Throws<ArgumentNullException>( () => target.AsString( null ) );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例6: TestAsString_Null_Success

		public void TestAsString_Null_Success()
		{
			var target = new MessagePackObject( default( string ) );
			Assert.IsNull( target.AsString() );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例7: TestAsString_IsNotString

		public void TestAsString_IsNotString()
		{
			var target = new MessagePackObject( 0 );
			Assert.Throws<InvalidOperationException>( () => target.AsString() );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例8: TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail

		public void TestAsString1_EncodingIsUtf32_SpecifyNotUtf32_Fail()
		{
			var target = new MessagePackObject( Encoding.UTF32.GetBytes( _japanese ) );
			var result = target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) );
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例9: TestAsString_EncodingMissmatch

		public void TestAsString_EncodingMissmatch()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			Assert.Throws<InvalidOperationException>( () => target.AsString() );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例10: TestAsString1_EncodingMissmatchAndThrowsDecoderFallbackException

		public void TestAsString1_EncodingMissmatchAndThrowsDecoderFallbackException()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			var result = target.AsString( new UTF8Encoding( encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true ) );
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例11: TestAsString1_EncodingIsNull

		public void TestAsString1_EncodingIsNull()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			var result = target.AsString( null );
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例12: TestAsString_IsNotString

		public void TestAsString_IsNotString()
		{
			var target = new MessagePackObject( 0 );
			target.AsString();
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例13: TestAsString_EncodingMissmatch

		public void TestAsString_EncodingMissmatch()
		{
			var target = new MessagePackObject( Encoding.Unicode.GetBytes( _japanese ) );
			var result = target.AsString();
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例14: TestAsString1_IsNotString

		public void TestAsString1_IsNotString()
		{
			var target = new MessagePackObject( 0 );
			target.AsString( Encoding.UTF32 );
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:5,代码来源:MessagePackObjectTest.Strings.cs

示例15: UnpackError

		/// <summary>
		///		Unpacks <see cref="RpcErrorMessage"/> from stream in the specified context.
		/// </summary>
		/// <param name="context"><see cref="ClientResponseContext"/> which stores serialized error.</param>
		/// <returns>An unpacked <see cref="RpcErrorMessage"/>.</returns>
		internal static RpcErrorMessage UnpackError( ClientResponseContext context )
		{
			Contract.Assert( context != null );
			Contract.Assert( context.ErrorBuffer != null );
			Contract.Assert( context.ErrorBuffer.Length > 0 );
			Contract.Assert( context.ResultBuffer != null );
			Contract.Assert( context.ResultBuffer.Length > 0 );

			MessagePackObject error;
			try
			{
				error = Unpacking.UnpackObject( context.ErrorBuffer );
			}
			catch ( UnpackException )
			{
				error = new MessagePackObject( context.ErrorBuffer.GetBuffer().SelectMany( segment => segment.AsEnumerable() ).ToArray() );
			}

			if ( error.IsNil )
			{
				return RpcErrorMessage.Success;
			}

			bool isUnknown = false;
			RpcError errorIdentifier;
			if ( error.IsTypeOf<string>().GetValueOrDefault() )
			{
				var asString = error.AsString();
				errorIdentifier = RpcError.FromIdentifier( asString, null );
				// Check if the error is truely Unexpected error.
				isUnknown = errorIdentifier.ErrorCode == RpcError.Unexpected.ErrorCode && asString != RpcError.Unexpected.Identifier;
			}
			else if ( error.IsTypeOf<int>().GetValueOrDefault() )
			{
				errorIdentifier = RpcError.FromIdentifier( null, error.AsInt32() );
			}
			else
			{
				errorIdentifier = RpcError.Unexpected;
				isUnknown = true;
			}

			MessagePackObject detail;
			if ( context.ResultBuffer.Length == 0 )
			{
				detail = MessagePackObject.Nil;
			}
			else
			{
				try
				{
					detail = Unpacking.UnpackObject( context.ResultBuffer );
				}
				catch ( UnpackException )
				{
					detail = new MessagePackObject( context.ResultBuffer.GetBuffer().SelectMany( segment => segment.AsEnumerable() ).ToArray() );
				}
			}

			if ( isUnknown )
			{
				// Unknown error, the error should contain original Error field as message.
				if ( detail.IsNil )
				{
					return new RpcErrorMessage( errorIdentifier, error.AsString(), null );
				}
				else
				{
					var details = new MessagePackObjectDictionary( 2 );
					details[ RpcException.MessageKeyUtf8 ] = error;
					details[ RpcException.DebugInformationKeyUtf8 ] = detail;
					return new RpcErrorMessage( errorIdentifier, new MessagePackObject( details, true ) );
				}
			}
			else
			{
				return new RpcErrorMessage( errorIdentifier, detail );
			}
		}
开发者ID:Indifer,项目名称:Test,代码行数:84,代码来源:ErrorInterpreter.cs


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