KnownTargetValueInjection usage from VB.NET WebForms

Sep 16, 2010 at 5:53 PM
Edited Sep 17, 2010 at 8:25 PM

I am attempting to use ValueInjecter in a VB .NET 4.0 Web Application.

I am trying to simply set some Textbox.Text properties from a simple class object.

I converted the C# example StringToTextBox class to VB.NET, but it fails at runtime when it cannot find the GetProps() method on my source object.

 

Option Infer On

Imports Omu.ValueInjecter
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class StringToTextBox
    Inherits KnownTargetValueInjection(Of Control)
    Protected Overrides Sub Inject(ByVal source As Object, ByRef target As Control)
        Dim sourceProps = source.GetProps()
    ....<cut>....
    End Sub
End Class

 

I have the Omu.ValueInjecter's DLL referenced and I have the Imports declaration at the top of the class.

I am even trying the very same source object class from your example, just converted to VB.NET:

 

   Dim o = New With { _
    .FirstName = "Jimmy", _
    .LastName = "Programmer", _
    .Address = "Internetz" _
   }

 

Calling it like this via the code-behind of a Form:

 

Me.InjectFrom(Of StringToTextBox)(o)

 

I can step through it and watch it go to the InjectFrom<T> generic method, then to the Map() method of that generic, and as soon as it hits the Inject() call, it transfers back to my overridden Inject()... so everything looks fine.  It just doesn't seem to know anything about the GetProps() object extension in PropertyInfosStorage.

It's got to be something stupid I'm doing.

Any ideas?

Thanks-

 

Sep 16, 2010 at 6:45 PM

Well I just realized I could call the extension method another way and actually get it to work.

Dim sourceProps = PropertyInfosStorage.GetProps(source)

Still not exactly sure why source.GetProps() isn't available..  but at least it works.

Thanks-

 

Coordinator
Sep 17, 2010 at 6:43 AM

Hi,

it looks like extension methods for object type don't work in VB.NET

http://stackoverflow.com/questions/3733119/extension-methods-from-c-dll-doesnt-work-as-extensions-in-vb-net

Cheers,

Omu

Sep 17, 2010 at 8:22 PM
Edited Sep 17, 2010 at 8:24 PM

I did not realize that.  Thanks for the info! 

'Love ValueInjecter, btw!  Extremely handy library-

Keep up the good work-