Re: knowing the interfaces that an object implements
- From: "Sanjay" <sanjays.singh@xxxxxxxxx>
- Date: Mon, 25 Apr 2005 18:26:02 +0530
hi,
can u give me the vb .net equivalent of this code ?
if(connection is IDisposable)
connection.Dispose();
It does not compile this way as u can't compare a type with an object.
thank u.
sanjay
"LOZANO-MORÁN, Gabriel" <gabriel.lozano@xxxxxxxxxxx> wrote in message
news:OKvAEUYSFHA.356@xxxxxxxxxxxxxxxxxxxxxxx
> As you can see there are several ways to do this :) it all depends on what
> you want.
>
> If you only need to check for the IDisposable interface I would indeed
> choose for Tiberius solution but you don't need to explicitly cast to
> IDisposable first because if the validation is true you are already sure
> that the Dispose() method exists.
>
> Eg:
> SqlConnection connection = new SqlConnection():
>
> if(connection is IDisposable)
> connection.Dispose();
>
> My solution was from a method I had written that accepts 2 parameters, the
> object to check and the name of an interface:
>
> Eg:
> public static bool ExistsInterface(object objectToCheck, string
> interfaceName)
> {
> if(objectToCheck.GetType().GetInterface(interfaceName) == null)
> return false;
> else
> return true;
> }
>
>
> Gabriel Lozano-Morán
>
>
.
- Follow-Ups:
- Re: knowing the interfaces that an object implements
- From: Richard Blewett [DevelopMentor]
- Re: knowing the interfaces that an object implements
- From: Jakob Christensen
- Re: knowing the interfaces that an object implements
- References:
- knowing the interfaces that an object implements
- From: Sanjay
- Re: knowing the interfaces that an object implements
- From: LOZANO-MORÁN, Gabriel
- Re: knowing the interfaces that an object implements
- From: Jakob Christensen
- Re: knowing the interfaces that an object implements
- From: Tiberiu Covaci[MCAD.NET]
- Re: knowing the interfaces that an object implements
- From: LOZANO-MORÁN, Gabriel
- knowing the interfaces that an object implements
- Prev by Date: error when updating .net framevork
- Next by Date: Re: error when updating .net framevork
- Previous by thread: Re: knowing the interfaces that an object implements
- Next by thread: Re: knowing the interfaces that an object implements
- Index(es):
Relevant Pages
|
Loading