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


C# MessagePackObject.AsDictionary方法代码示例

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


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

示例1: RpcException

		/// <summary>
		///		Initialize new instance with unpacked data.
		/// </summary>
		/// <param name="rpcError">
		///		Metadata of error. If you specify null, <see cref="MsgPack.Rpc.RpcError.RemoteRuntimeError"/> is used.
		///	</param>
		/// <param name="unpackedException">
		///		Exception data from remote MessagePack-RPC server.
		///	</param>
		/// <exception cref="SerializationException">
		///		Cannot deserialize instance from <paramref name="unpackedException"/>.
		/// </exception>
		protected internal RpcException( RpcError rpcError, MessagePackObject unpackedException )
			: this( rpcError, unpackedException.GetString( MessageKeyUtf8 ), unpackedException.GetString( DebugInformationKeyUtf8 ) )
		{
			if ( unpackedException.IsDictionary )
			{
				MessagePackObject mayBeArray;
				if ( unpackedException.AsDictionary().TryGetValue( _remoteExceptionsUtf8, out mayBeArray ) && mayBeArray.IsArray )
				{
					var array = mayBeArray.AsList();
					this._remoteExceptions = new RemoteExceptionInformation[ array.Count ];
					for ( int i = 0; i < this._remoteExceptions.Length; i++ )
					{
						if ( array[ i ].IsList )
						{
							this._remoteExceptions[ i ] = new RemoteExceptionInformation( array[ i ].AsList() );
						}
						else
						{
							// Unexpected type.
							Debug.WriteLine( "Unexepcted ExceptionInformation at {0}, type: {1}, value: \"{2}\".", i, array[ i ].UnderlyingType, array[ i ] );
							this._remoteExceptions[ i ] = new RemoteExceptionInformation( new MessagePackObject[] { array[ i ] } );
						}
					}
				}
			}

#if !SILVERLIGHT && !MONO
			this.RegisterSerializeObjectStateEventHandler();
#endif
		}
开发者ID:Indifer,项目名称:Test,代码行数:42,代码来源:RpcException.Propagation.cs

示例2: MsgUnPackTable

 public static bool MsgUnPackTable(out LuaTable luatable, ref MessagePackObject pObj)
 {
     LuaTable result = new LuaTable();
     luatable = result;
     var mPk = pObj.AsDictionary();
     bool isString = false;
     string key;
     object value;
     foreach (var item in mPk)
     {
         //parse for key
         MessagePackObject mKey = item.Key;
         if (mKey.IsRaw)
         {
             key = mKey.AsString();
             isString = true;
         }
         else if (true == mKey.IsTypeOf<double>())
         {
             key = mKey.AsDouble().ToString();
         }
         else
         {
             LoggerHelper.Error("key type error");
             return false;
         }
         //parse for value
         MessagePackObject mValue = item.Value;
         if (mValue.IsRaw)
         {
             value = mValue.AsString();
         }
         else if (mValue.IsDictionary)
         {
             LuaTable luatbl;
             MsgUnPackTable(out luatbl, ref mValue);
             value = luatbl;
         }
         else if (true == mValue.IsTypeOf<bool>())
         {
             value = mValue.AsBoolean();
         }
         else if (true == mValue.IsTypeOf<double>())
         {
             value = mValue.AsDouble();
         }
         else
         {
             LoggerHelper.Error("value type error");
             return false;
         }
         result.Add(key, isString, value);
         isString = false;
     }
     return true;
 }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:56,代码来源:Utils.cs

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

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