Sorry for replaying to myself. I think I understand why you are using
it. You don't know the type of interface you have to test for at
compile time.
There is no other way than to know in which interfaces that you are
interested. Then you can check if they are in GetInterfaces().
Like this:
foreach (Type expectedInteface in ExpectedInterfaces)
{
foreach (Type implementedInterface in thing.GetType().GetInterfaces
())
{
if (expectedInterface == implementedInterface)
{
// it is implementing expectedInterface.
}
}
}
You can also mark the expected interfaces with an attribute or
consider the assembly or the namespace. Note that this is not a Rhino
Mocks problem at all. You can't know "the" interface an object
implements, because there could be many, there is no "main" interface.
PS: We have a enum called "BusinessType" which represents the type an
object represents in a high level. A BusinessObject returns the
BusinessType it implements by a property. This decouples business
logic from .NET types. There is no direct mapping between
BusinessTypes and .NET types.
On 9 Apr., 09:57, Stefan Steinegger <[email protected]> wrote:
> Um. Actually I don't really understand why you need this. The whole
> sense of an interface is that you don't need to know the class that is
> implementing it. If you want to see if it is an implementation of the
> certain interface in some kind, just write:
>
> if (thing is IAuthoredBy)
> {
> // it is implementing the interface...
>
> }
>
> or
>
> IAuthoredBy authoredBy = thing as IAuthoredBy;
> if (authoredBy != null)
> {
> // use authoredBy
>
> }
>
> On 7 Apr., 13:59, Iain Waddell <[email protected]> wrote:
>
> > > As far as I know there is no way to get the interface used from the
> > > internals of the proxy itself since DynamicProxy doesn't store this
> > > information.
>
> > > I cannot see where MSDN says not to use GetInterfaces(). Just don't assume
> > > it is the first once since the proxy will also implement ISerializable and
> > > IProxyTargetAccessor.
>
> > >http://msdn.microsoft.com/en-us/library/system.type.getinterfaces.aspx
>
> > Sorry, I was looking at the wrong GetInterfaces() help. I don't find the
> > latest MSDN help nearly as intuitive as earlier versions.
>
> > Iain
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---