Query for an Interface from a Object

  • Thread starter Thread starter Kiran
  • Start date Start date
K

Kiran

Hi,

I was wondering if there is any method that I can override on my Object
which will be called when somewhere try's to Query for an interface from my
object. for e.g.

IMyInterface x = myObject as IMyInterface ;

will there be any method that will be called in myObject which can be used
to change the default behavior of this QueryInterface?

Regards
Kiran
 
Hi Kiran:

No, I do not believe so.

The closest one could get is to create a user defined conversion, but
it is a compiler error to create a user defined conversion to an
interface, so the following code is illegal:

interface IBar
{
void DoBar();
}

class Foo : IBar
{
public static explicit operator IBar(Foo f)
{
Console.WriteLine("Foo::operator_IBar");
}

public void DoBar()
{
Console.Write("Foo::DoBar");
}
}


HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top