Home All Groups Group Topic Archive Search About

Doing "using" with CodeDom?

Author
26 Apr 2007 4:18 PM
Kevin Burton
Is there any way to do "using" with the CodeDom?

using(SqlConnection connnection = new SqlConnection("..."))
{
}

Kevin

Author
27 Apr 2007 7:17 AM
Damien
On Apr 26, 5:18 pm, Kevin Burton
<KevinBur***@discussions.microsoft.com> wrote:
> Is there any way to do "using" with the CodeDom?
>
> using(SqlConnection connnection = new SqlConnection("..."))
> {
>
> }
>
> Kevin

No, because using is a language specific facility. You'll have to go
the long way around and do:
SQLConnection connection = new SqlConnection("...");
try
{

}
finally
{
  connection.Dispose();
}

which is the equivalent. I'm a VBer, and face similar hurdles with
SyncLock and While (both of which *do* have equivalents in C#, but are
somehow ommitted from the CodeDOM)

Damien

AddThis Social Bookmark Button