[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Getting type of anonymous interface

Posted on 2014-08-18
Medium Priority
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 36

Accepted Solution

Miguel Oz earned 2000 total points
ID: 40269140
You could use the IS operator:
if (spSimpleResult is IResultOf(Of spSimpleResult)) then

where spSimpleResult is the instance to check.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 41695272
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Integration Management Part 2

872 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