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


C# MessagePackObject.IsTypeOf方法代码示例

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


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

示例1: UnpackFromMessage

		public void UnpackFromMessage( MessagePackObject messagePackObject )
		{
		
			if (! messagePackObject.IsTypeOf<IList<MessagePackObject>>().GetValueOrDefault() )
			{
				throw new ArgumentException(messagePackObject.UnderlyingType.ToString());
			}

			var asList = messagePackObject.AsList();
			if ( asList.Count != 5 )
			{
				throw new ArgumentException();
			}

			uri = asList[ 0 ].AsString();
			title = asList[ 1].AsString();
			width = asList[ 2 ].AsInt32();
			height = asList[ 3 ].AsInt32();
			size = asList[ 4 ].AsInt32();
		}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:20,代码来源:Image.cs

示例2: Dump

		private static void Dump( MessagePackObject obj, StringBuilder buffer, int indent )
		{
			if ( obj.IsNil )
			{
				buffer.Append( ' ', indent * 2 ).Append( "(null)" ).AppendLine();
			}
			else if ( obj.IsTypeOf<IList<MessagePackObject>>().GetValueOrDefault() )
			{
				buffer.Append( ' ', indent * 2 ).AppendLine( "(" );

				foreach ( var child in obj.AsList() )
				{
					Dump( child, buffer, indent + 1 );
				}

				buffer.Append( ' ', indent * 2 ).AppendLine( ")" );
			}
			else if ( obj.IsTypeOf<IDictionary<MessagePackObject, MessagePackObject>>().GetValueOrDefault() )
			{
				buffer.Append( ' ', indent * 2 ).AppendLine( "{" );

				foreach ( var child in obj.AsDictionary() )
				{
					Dump( child.Key, buffer, indent + 1 );
					buffer.Append( ' ', ( indent + 1 ) * 2 ).AppendLine( "= " );
					Dump( child.Value, buffer, indent + 2 );
				}

				buffer.Append( ' ', indent * 2 ).AppendLine( "}" );
			}
			else
			{
				buffer.Append( ' ', indent * 2 ).Append( obj ).Append( " : " ).Append( obj.UnderlyingType ).AppendLine();
			}
		}
开发者ID:eslo,项目名称:msgpack-cli,代码行数:35,代码来源:PackUnpackTest.cs

示例3: 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

示例4: FromMessage

        /// <summary>
        ///		Create <see cref="RpcException"/> or dervied instance which corresponds to sepcified error information.
        /// </summary>
        /// <param name="error">Basic error information. This information will propagate to client.</param>
        /// <param name="errorDetail">Detailed error information, which is usally debugging purpose only, so will not propagate to client.</param>
        /// <returns>
        ///		<see cref="RpcException"/> or dervied instance which corresponds to sepcified error information.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///		<paramref name="error"/> is <see cref="MessagePackObject.IsNil">nil</see>.
        /// </exception>
        public static RpcException FromMessage( MessagePackObject error, MessagePackObject errorDetail )
        {
            // TODO: Application specific customization
            // TODO: Application specific exception class

            if ( error.IsNil )
            {
                throw new ArgumentException( "'error' must not be nil.", "error" );
            }

            // Recommeded path
            if ( error.IsTypeOf<byte[]>().GetValueOrDefault() )
            {
                string identifier = null;
                try
                {
                    identifier = error.AsString();
                }
                catch ( InvalidOperationException ) { }

                int? errorCode = null;

                if ( errorDetail.IsTypeOf<IDictionary<MessagePackObject, MessagePackObject>>().GetValueOrDefault() )
                {
                    var asDictionary = errorDetail.AsDictionary();
                    MessagePackObject value;
                    if ( asDictionary.TryGetValue( _errorCodeKeyUtf8, out value ) && value.IsTypeOf<int>().GetValueOrDefault() )
                    {
                        errorCode = value.AsInt32();
                    }
                }

                if ( identifier != null || errorCode != null )
                {
                    RpcError rpcError = RpcError.FromIdentifier( identifier, errorCode );
                    return rpcError.ToException( errorDetail );
                }
            }

            // Other path.
            return new UnexpcetedRpcException( error, errorDetail );
        }
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:53,代码来源:RpcException.cs


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