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


C# Unpacker.ReadString方法代码示例

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


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

示例1: UnpackStringValue

		public static string UnpackStringValue( Unpacker unpacker, Type objectType, String memberName )
		{
			if ( unpacker == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "unpacker" );
			}

			if ( objectType == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "objectType" );
			}

			if ( memberName == null )
			{
				SerializationExceptions.ThrowArgumentNullException( "memberName" );
			}

#if ASSERT
			Contract.Assert( unpacker != null );
			Contract.Assert( objectType != null );
			Contract.Assert( memberName != null );
#endif // ASSERT

			// ReSharper disable once RedundantAssignment
			var ctx = default( UnpackerTraceContext );
			InitializeUnpackerTrace( unpacker, ref ctx );

			try
			{
				string result;
				if ( !unpacker.ReadString( out result ) )
				{
					SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, null );
				}

				Trace( ctx, "ReadDirect", unpacker, memberName );

				return result;
			}
			catch ( MessageTypeException ex )
			{
				SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, ex );
				return default( string ); // never reaches.
			}
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:45,代码来源:UnpackHelpers.direct.cs

示例2: UnpackStringValue

		public static string UnpackStringValue( Unpacker unpacker, Type objectType, String memberName )
		{
			try
			{
				string result;
				if ( !unpacker.ReadString( out result ) )
				{
					throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, null );
				}

				return result;
			}
			catch ( MessageTypeException ex )
			{
				throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, ex );
			}
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:17,代码来源:UnpackHelpers.direct.cs

示例3: Decode

		public static Type Decode( Unpacker unpacker )
		{
			if ( !unpacker.IsArrayHeader )
			{
				throw new SerializationException( "Type info must be non-nil array." );
			}

			if ( unpacker.ItemsCount != 5 )
			{
				throw new SerializationException( "Components count of type info is not valid." );
			}

			string compressedTypeName;
			if ( !unpacker.ReadString( out compressedTypeName ) )
			{
				throw new SerializationException( "Failed to decode type name component." );
			}

			string assemblySimpleName;
			if ( !unpacker.ReadString( out assemblySimpleName ) )
			{
				throw new SerializationException( "Failed to decode assembly name component." );
			}

			byte[] version;
			if ( !unpacker.ReadBinary( out version ) )
			{
				throw new SerializationException( "Failed to decode version component." );
			}

			string culture;
			if ( !unpacker.ReadString( out culture ) )
			{
				throw new SerializationException( "Failed to decode culture component." );
			}

			byte[] publicKeyToken;
			if ( !unpacker.ReadBinary( out publicKeyToken ) )
			{
				throw new SerializationException( "Failed to decode public key token component." );
			}

#if !NETFX_CORE
			var assemblyName =
				new AssemblyName
				{
					Name = assemblySimpleName,
					Version =
						new Version(
							BitConverter.ToInt32( version, 0 ),
							BitConverter.ToInt32( version, 4 ),
							BitConverter.ToInt32( version, 8 ),
							BitConverter.ToInt32( version, 12 )
						),
					CultureInfo = 
						String.IsNullOrEmpty( culture ) 
						? null 
#if !WINDOWS_PHONE && !SILVERLIGHT
						: CultureInfo.GetCultureInfo( culture ),
#else
						: new CultureInfo( culture ),
#endif //  !WINDOWS_PHONE
				};
			assemblyName.SetPublicKeyToken( publicKeyToken );
#else
			var assemblyName = 
				new AssemblyName( 
					String.Format( 
						CultureInfo.InvariantCulture, 
						"{0},Version={1},Culture={2},PublicKeyToken={3}",
						assemblySimpleName,
						new Version(
							BitConverter.ToInt32( version, 0 ),
							BitConverter.ToInt32( version, 4 ),
							BitConverter.ToInt32( version, 8 ),
							BitConverter.ToInt32( version, 12 )
						),
						String.IsNullOrEmpty( culture ) ? "neutral" : culture,
						( publicKeyToken == null || publicKeyToken.Length == 0 ) ? "null" : Binary.ToHexString( publicKeyToken, false )
					)
				);
#endif // !NETFX_CORE

			return
				Assembly.Load(
					assemblyName
#if SILVERLIGHT
					.ToString()
#endif // SILVERLIGHT
				).GetType(
					compressedTypeName.StartsWith( Elipsis, StringComparison.Ordinal )
					? assemblySimpleName + compressedTypeName
					: compressedTypeName
#if !NETFX_CORE
					, throwOnError: true
#endif // !NETFX_CORE
				);
		}
	}
开发者ID:josiahdecker,项目名称:msgpack-cli,代码行数:99,代码来源:TypeInfoEncoder.cs


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