Getting type of anonymous interface

Posted on 2014-08-18
Last Modified: 2016-07-11
Given an interface like this:

Public Interface IResultOf(Of T As spBaseResult)

    Sub SetData(ByVal data As T)

End Interface

Open in new window

And a class implementing the interface like this...

Public Class ucStandardResult
    Implements IResultOf(Of spSimpleResult)

    Public Sub SetData(data As spSimpleResult) Implements IResultOf(Of spSimpleResult).SetData

    End Sub

End Class

Open in new window

How can I externally establish the anonymous type that the class supports. I.e. I want to do something like.

If GetType(IResultOf(of spSimpleResult)).IsAssignableFrom(Instance.GetType) then....

Open in new window

Or to put it another way, if I had an object of type spSimpleResult, how would I go about finding, through code at runtime, a type that supports the interface IResultOf(Of spSimpleResult)

I hope that is clear!!!

Thanks in advance, Kenny
Question by:kendolondon
    LVL 35

    Accepted Solution

    You could use the IS operator:
    if (spSimpleResult is IResultOf(Of spSimpleResult)) then

    where spSimpleResult is the instance to check.
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    The proposed answer is only partially correct. is works this way in C#; it does not work this way in VB.NET. The VB.NET equivalent to C#'s is would be the TypeOf operator.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now