1

I'm wondering if it's possible to do something like the following?

Public Class MyClass

    Public t As Type = Reflection.Assembly.Load("AssemblyPath").GetType("TypePath")

    Public Function Foo() As t
        [...]
    End Function

End Class

In other words, I'd like to use reflection to obtain type references which I would then use as return types or method parameter types. Can I do this, and if so, how? Thanks.

thomas
  • 61
  • 1
  • 1
  • 9

1 Answers1

2

No, basically. You would have to return object or maybe some interface / base-class from a library referenced by both assemblies. Or use duck-typing via dynamic (or whatever that is in VB terms - sorry, I don't do much VB these days). Or, of course, just add a reference to that dll.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • +1. For completeness, there's no direct equivalent to `dynamic` in VB.net, you [have to turn Option Strict Off](http://stackoverflow.com/questions/2889974/vb-net-equivalent-for-c-sharp-dynamic-with-option-strict-on) – MarkJ Sep 05 '13 at 10:53
  • Adding a reference would be the easiest option, but in this case it'd create a cyclical dependency for me. Thanks for the help! – thomas Sep 05 '13 at 14:30