本文整理汇总了C#中MsgPack.Serialization.Reflection.TracingILGenerator.BeginFinallyBlock方法的典型用法代码示例。如果您正苦于以下问题:C# TracingILGenerator.BeginFinallyBlock方法的具体用法?C# TracingILGenerator.BeginFinallyBlock怎么用?C# TracingILGenerator.BeginFinallyBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MsgPack.Serialization.Reflection.TracingILGenerator
的用法示例。
在下文中一共展示了TracingILGenerator.BeginFinallyBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitUnpackerEndReadSubtree
public static void EmitUnpackerEndReadSubtree( TracingILGenerator il, LocalBuilder subtreeUnpacker )
{
Contract.Requires( il != null );
Contract.Requires( subtreeUnpacker != null );
/*
* finally
* {
* if( subtreeUnpacker != null )
* {
* subtreeUnpacker.Dispose();
* }
* }
*/
il.BeginFinallyBlock();
il.EmitAnyLdloc( subtreeUnpacker );
var endIf = il.DefineLabel( "END_IF" );
il.EmitBrfalse_S( endIf );
il.EmitAnyLdloc( subtreeUnpacker );
il.EmitAnyCall( Metadata._IDisposable.Dispose );
il.MarkLabel( endIf );
il.EndExceptionBlock();
}
示例2: EmitForEach
//.........这里部分代码省略.........
if ( typeof( IDisposable ).IsAssignableFrom( traits.GetEnumeratorMethod.ReturnType ) )
{
il.BeginExceptionBlock();
}
var startLoop = il.DefineLabel( "START_LOOP" );
il.MarkLabel( startLoop );
var endLoop = il.DefineLabel( "END_LOOP" );
var enumeratorType = traits.GetEnumeratorMethod.ReturnType;
MethodInfo moveNextMethod = enumeratorType.GetMethod( "MoveNext", Type.EmptyTypes );
PropertyInfo currentProperty = traits.GetEnumeratorMethod.ReturnType.GetProperty( "Current" );
if ( moveNextMethod == null )
{
moveNextMethod = Metadata._IEnumerator.MoveNext;
}
if ( currentProperty == null )
{
if ( enumeratorType == typeof( IDictionaryEnumerator ) )
{
currentProperty = Metadata._IDictionaryEnumerator.Current;
}
else if ( enumeratorType.IsInterface )
{
if ( enumeratorType.IsGenericType && enumeratorType.GetGenericTypeDefinition() == typeof( IEnumerator<> ) )
{
currentProperty = typeof( IEnumerator<> ).MakeGenericType( traits.ElementType ).GetProperty( "Current" );
}
else
{
currentProperty = Metadata._IEnumerator.Current;
}
}
}
Contract.Assert( currentProperty != null, enumeratorType.ToString() );
// iterates
if ( traits.GetEnumeratorMethod.ReturnType.IsValueType )
{
il.EmitAnyLdloca( enumerator );
}
else
{
il.EmitAnyLdloc( enumerator );
}
il.EmitAnyCall( moveNextMethod );
il.EmitBrfalse( endLoop );
bodyEmitter(
il,
() =>
{
if ( traits.GetEnumeratorMethod.ReturnType.IsValueType )
{
il.EmitAnyLdloca( enumerator );
}
else
{
il.EmitAnyLdloc( enumerator );
}
il.EmitGetProperty( currentProperty );
}
);
il.EmitBr( startLoop );
il.MarkLabel( endLoop );
// Dispose
if ( typeof( IDisposable ).IsAssignableFrom( traits.GetEnumeratorMethod.ReturnType ) )
{
il.BeginFinallyBlock();
if ( traits.GetEnumeratorMethod.ReturnType.IsValueType )
{
var disposeMethod = traits.GetEnumeratorMethod.ReturnType.GetMethod( "Dispose" );
if ( disposeMethod != null && disposeMethod.GetParameters().Length == 0 && disposeMethod.ReturnType == typeof( void ) )
{
il.EmitAnyLdloca( enumerator );
il.EmitAnyCall( disposeMethod );
}
else
{
il.EmitAnyLdloc( enumerator );
il.EmitBox( traits.GetEnumeratorMethod.ReturnType );
il.EmitAnyCall( Metadata._IDisposable.Dispose );
}
}
else
{
il.EmitAnyLdloc( enumerator );
il.EmitAnyCall( Metadata._IDisposable.Dispose );
}
il.EndExceptionBlock();
}
}