Re: knowing the interfaces that an object implements



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
>
>


.



Relevant Pages

  • Re: knowing the interfaces that an object implements
    ... 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 ... SqlConnection connection = new SqlConnection: ... string ...
    (microsoft.public.dotnet.framework)
  • Re: try positioning the darknesss average marker and Ann will chop you
    ... compare. ... Will you reveal near the section, if Jezebel o'clock ... merges the interface? ... If the premier laboratorys can instruct fairly, ...
    (sci.crypt)
  • Re: How to work with XML in MFC?
    ... Compare that to a couple of days to really get your head around the MSXML COM interface. ... I am interested in reading and parsing MusicXML documents and I'll need the whole thing in memory to get what I need out of them. ...
    (microsoft.public.vc.mfc)
  • Re: Testing an Assembly to see if it implements a give interface
    ... you can compare full type names: ... "Wayne Wise" escribió en el mensaje ... > validates against the interface in my project. ... >>> I have an application that gets all the assemblies in a folder ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Performance difference of switch statement or delegate?
    ... Since all standardtypes already implements the IComparable interface and you ... int doThisByType(object compareA, object compareB) ... > int Compare(object valueA, object valueB) ... > public class StringComparer: ITypeComparer ...
    (microsoft.public.dotnet.framework.clr)

Loading