VB reflection in for each loop

I'm attempting to use an unknown type in a for each loop as per the following code:

private sub ReflectThis(ByVal rawData As Object())
  Dim dataType As Type = rawData(0).GetType()
  Dim properties As PropertyInfo() = dataType.getProperties()
  For Each item As dataType In rawData ''//AAAA
    For Each property As System.Reflection.PropertyInfo properties
      ''//reflected code use here

The issue that I get is on the line marked AAAA. It complains that 'dataType' is not declared, which I take to mean it does not exist as a proper class.

The intent is to call a web service elsewhere, and regardless of which web service I call, use reflection to add the resulting data struct object's information to a database.

What, if any, are the restrictions on doing something like

Dim myObject As variableInstanceOfTypeObjectHere

or am I making a more fundamental error? If I'm right, what are the workarounds, if any?

Answers


When you declare a variable "As" a type, that means you know the type at compile time. That lets the compiler check what you're doing with it. In this case, you don't know the type at compile time - you're getting it at execution time. All you know is that each item is an object - so either don't specify the type (as suggested by Joel) or specify it as Object:

For Each item As Object In rawData ''//AAAA

Just don't specify the type:

For Each item in rawData

Need Your Help

Recommend a linux-based Site Search Engine?

search search-engine

I need a site search engine to provide search for my members-only content. I've previously used Fluid Dynamics Search Engine but was wondering if there was anything that's been more recently update...

Is there an omniauth strategy for Google login using openid?

ruby-on-rails ruby openid omniauth

I know there's a google-apps strategy which uses openid. And I know it's possible to configure Omniauth's generic openid strategy to work with regular (non-apps) google accounts.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.