Una aporte mas a la confusión general....

Les cuento algo que existe en c#, no se si esta disponible en vb, el
operador as..

En C# uno podria hacer una conversion de tipo segura, evitando una exception
verificando primero con is, ejemplo:

            IServiceProvider isp=null;
            if (this is IServiceProvider)
                ips = (IServiceProvider)this;

Una forma mas elegante, y tambien mas eficiente si miran el codigo msil
resultante, es usar el operador as, ejemplo:

            IServiceProvider isp = this as IServiceProvider;

Esto último hace lo mismo que el ejemplo anterior, si this no implementa
IServiceProvider ips valdra null.  :))

Saben si hay equivalente en vb???, busque y no lo encontre....

Bueno, me parecio que valia la pena....  :))

Saludos

Daniel Calvin


El día 24/08/07, Luis Capra <[EMAIL PROTECTED]> escribió:
>
> Yo para hacer eso, en C# hice un metodo:
>
>         public static bool IsInterfaceImplemented(Type type, Type
> interfaceType)
>         {
>             return type.FindInterfaces(
>                        new TypeFilter(
>                            delegate(Type _type, object _filter)
>                                {
>                                    return (_type.Name == ((Type)
> _filter).Name) &&
>                                           (_type.Namespace == ((Type)
> _filter).Namespace);
>                                }
>                            ),
>                        interfaceType
>                        ).Length == 1;
>         }
>
> Peor por lo visto es mucho mas sencillo lo otro :=)
>
>
>
>
>
> On 8/24/07, Carlos Marcelo Santos <[EMAIL PROTECTED]> wrote:
> >
> >  ¡¡¡Muchas Gracias!!!
> >
> > Auspiciosa manera de comenzar un viernes…
> >
> >
> >
> > Carlos Marcelo Santos.
> >
> >
> >  ------------------------------
> >
> > *From:* [email protected] [mailto:[EMAIL PROTECTED] *On Behalf Of *
> > [EMAIL PROTECTED]
> > *Sent:* Viernes, 24 de Agosto de 2007 02:39 a.m.
> > *To:* [email protected]
> > *Subject:* [puntonet] Saber si un objeto implementa una interface (Ex:
> > OT rdp)
> >
> >
> >
> > If TypeOf miControl Is ISerializable Then
> >
> >
> >
> > Saludos
> >
> > Leonardo
> >
> >
> >  ------------------------------
> >
> > *De:* Carlos Marcelo Santos [mailto:[EMAIL PROTECTED]
> > *Enviado el: * Jueves, 23 de Agosto de 2007 09:53 p.m.
> > *Para:* [email protected]
> > *Asunto:* [puntonet] Saber si un objeto implementa una interface (Ex: OT
> > rdp)
> >
> >
> >
> > * Replies will be sent through Spamex to [email protected]
> > * For additional info click -> www.spamex.com/i/?v=13137989
> >
> >
> >
> > Hola Diego:
> >
> > Gracias por prolijar el subject.
> >
> > No funciona para este caso
> >
> > If miControl Is ISerializable Then
> >
> > Da error
> >
> > Y ahora probé
> >
> > If miControl = ISerializable Then
> >
> > También da error
> >
> >
> >
> > Gracias.
> >
> >
> >
> > Carlos Marcelo Santos .
> >
> >
> >  ------------------------------
> >
> > *From:* [email protected] [mailto:[EMAIL PROTECTED] *On Behalf Of *Diego 
> > Jancic
> > *Sent:* Jueves, 23 de Agosto de 2007 09:42 p.m.
> > *To:* [email protected]
> > *Subject:* [puntonet] Saber si un objeto implementa una interface (Ex:
> > OT rdp)
> >
> >
> >
> > Hola,
> >
> > Cambie el asunto del email para que se entienda un poco mas de que
> > estamos hablando…
> >
> >
> >
> > Según un traductor de C# a VB.NET <http://vb.net/>, esto:
> >
> >
> >
> > bool a = myControl is ISerializable;
> >
> >
> >
> > se traduce a esto:
> >
> >
> >
> > Dim a As Boolean = (myControl = ISerializable)
> >
> >
> >
> >
> >
> > Espero que te sirva.
> >
> >
> >
> > Saludos,
> > Diego
> >
> >
> >
> >
> >  ------------------------------
> >
> > *From:* [email protected] [mailto:[EMAIL PROTECTED] *On Behalf Of *Carlos 
> > Marcelo Santos
> > *Sent:* Jueves, 23 de Agosto de 2007 09:34 p.m.
> > *To:* [email protected]
> > *Subject:* [puntonet] OT rdp
> >
> >
> >
> > Hola Gente:
> >
> > ¿Cómo se pregunta en VB si un objeto implementa una interface?
> >
> > Lo que en C# sería
> >
> > if (myControl is ISerializable)
> >
> >
> >
> > Gracias.
> >
> >
> >
> > Carlos Marcelo Santos .
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.5.484 / Virus Database: 269.12.2/967 - Release Date:
> > 22/08/2007 06:51 p.m.
> >
>
>


-- 
Daniel A. Calvin
Cooperator Team Member
http://www.cooperator.com.ar
Microsoft Certified Professional

Responder a