title: Public member 'ToCSVValue' on type 'Integer' not found for VB Extension method
body: <p>I am trying to write a ToCSV() extension in VB based on <a href="http://www.hanselman.com/blog/?date=2010-02-04" rel="nofollow">Scott Hanselman's blog</a>.  It could be that my C# to VB is not correct, but it all seems right.
  I added a module with:</p>
  
  <pre><code>&lt;System.Runtime.CompilerServices.Extension&gt;
  Public Function ToCSV(Of T)(items As IEnumerable(Of T)) As String
      Try
  
          Dim csvBuilder = New StringBuilder()
          Dim properties = GetType(T).GetProperties()
  
          For Each item As T In items
  
              '' Test Code
              Dim newline As String = ""
              For Each l2 As Reflection.PropertyInfo In properties
  
                  ' This works
                  newline &amp;= l2.GetValue(item, Nothing)
  
                  ' This works too
                  Dim int As Integer = 1234
                  Dim s As String = int.ToCSVValue()
  
                  'This works
                  Dim nl = l2.GetValue(item, Nothing)
  
                  ' This blows up with "Public member 'ToCSVValue' on type 'Integer' not found."  
                  ' The Debugger type shows "Object {Integer}" which I assume to mean that the debugger interprets the object as an integer.
                  nl = nl.ToCSVValue()
              Next
  
              ' Original code
              Dim line As String = String.Join(",", properties.Select(Function(p) p.GetValue(item, Nothing).ToCSVValue()).ToArray())
              csvBuilder.AppendLine(line)
          Next
  
          Return csvBuilder.ToString()
  
      Catch ex As Exception
          Throw
      End Try
  
  End Function
  
  
  &lt;System.Runtime.CompilerServices.Extension&gt;
  Private Function ToCSVValue(Of T)(item As T) As String
  
      If item Is Nothing Then
          Return """"""
      End If
  
      If TypeOf item Is String Then
          Return String.Format("""{0}""", item.ToString().Replace("""", "\"""))
      End If
      Dim dummy As Double
      If Double.TryParse(item.ToString(), dummy) Then
          Return String.Format("{0}", item)
      End If
      Return String.Format("""{0}""", item)
  
  End Function
  </code></pre>
  
  <p>When I call it with something like:</p>
  
  <pre><code>Dim s As String = ctx.Customers.Where(Function(x) x.CustomerID = 123456).Select(Function(x) New With {.CustomerID = x.CustomerID, .CustomerName = x.CustomerName}).ToCSV()
  </code></pre>
  
  <p>it gets to the function ToCSV just fine.  It recognizes the items passed in.  It pulls out the first item and sees that there are the 2 fields in it.  All good!</p>
  
  <p>The GetValue() works just fine.</p>
  
  <p>If I create a static integer and call ToCSVValue on it, it works fine.
  If I create a static string and  call ToCSVValue on it, it works fine.</p>
  
  <p>When I call ToCSVValue on the GetValue() I get:
  Public member 'ToCSVValue' on type 'Integer' not found.</p>
  
  <p>Likewise, if I have just strings in the dataset, I get:
  Public member 'ToCSVValue' on type 'String' not found.</p>
  
  <p>Ideally this would work as it is in the "Original code" section and I can kill all this other test code.</p>
  
  <p>Can anyone tell me what is happening and why the "(Of T)" is not working the get GetValue() types, but it is for the directly cast types?</p>