using System;
using System.Reflection;
public struct Finally : IDisposable
{
public Finally(object target, string methodName)
{
this.target = target;
this.methodName = methodName;
}
public void Dispose()
{
Type t = target.GetType();
MethodInfo method = t.GetMethod(methodName);
if (method != null) {
t.InvokeMember(
methodName, BindingFlags.InvokeMethod,
target, new object[0] );
}
}
private readonly object target;
private readonly string methodName;
}