本文整理汇总了C#中Unpacker.ReadBinary方法的典型用法代码示例。如果您正苦于以下问题:C# Unpacker.ReadBinary方法的具体用法?C# Unpacker.ReadBinary怎么用?C# Unpacker.ReadBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Unpacker
的用法示例。
在下文中一共展示了Unpacker.ReadBinary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnpackBinaryValue
public static byte[] UnpackBinaryValue( 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
{
byte[] result;
if ( !unpacker.ReadBinary( out result ) )
{
SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, null );
}
Trace( ctx, "ReadDirect", unpacker, memberName );
return result;
}
catch ( MessageTypeException ex )
{
SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, ex );
return default( byte[] ); // never reaches.
}
}
示例2: UnpackBinaryValue
public static byte[] UnpackBinaryValue( Unpacker unpacker, Type objectType, String memberName )
{
try
{
byte[] result;
if ( !unpacker.ReadBinary( out result ) )
{
throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, null );
}
return result;
}
catch ( MessageTypeException ex )
{
throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, ex );
}
}
示例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
);
}
}