c# - Version-independent code for Rfc2898DeriveBytes (has Dispose on .NET 4.0 but not on 2.0) -
i'm writing small .net 2.0 compatible assembly uses rfc2898derivebytes
. on .net 2.0 rfc2898derivebytes
not implement idisposable
, while in .net 4.0 rfc2898derivebytes
implement idisposable
.
my assembly loaded in .net 4.0 applications , in .net 2.0 applications.
do need dispose
rfc2898derivebytes
using .net 4.0 or can ignore memorystream
? if so, how can write .net 2.0 , .net 4.0 compatible code, calling dispose
on .net 4.0? (at best without reflection , on.)
i guess not using dispose
on class not dangerous because idisposable
comes abstract
derivebytes
-class.
you could:
rfc2898derivebytes rfc = null; try { var salt = new byte[128]; rfc = new rfc2898derivebytes("password", salt); } { idisposable disp = rfc idisposable; if (disp != null) { disp.dispose(); } }
even roslyn, compiler doesn't remove as idisposable
: http://goo.gl/oobkzv (right pane, in release mode, optimizations active)
(note i'm not replication using
pattern... have initialized rfc
variable inside try
/finally
instead of outside... there no practical difference)
Comments
Post a Comment