Re: knowing the interfaces that an object implements
- From: "LOZANO-MORÁN, Gabriel" <gabriel.lozano@xxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 12:52:39 +0200
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: Sanjay
- 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]
- knowing the interfaces that an object implements
- Prev by Date: Re: knowing the interfaces that an object implements
- Next by Date: Re: Gen Question - Verify Web Page
- 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