title: Do These Extension Methods Look Correct?
body: <p>In VB.NET, I am creating extension methods for the SqlParameterCollection class so that I can add "detailed" parameters in one line of code. I understand that the .AddWithValue method will cause SQL Server to re-evaluate an SQL Server execution plan each time a Stored Procedure is called via an SqlCommand with SqlParameter objects that do not specify the size of alphanumeric data types (i.e. VarChar or NVarChar). In other words, .AddWithValue is a bad idea except for types like INT data types where the size of the data type is constant.</p>
  
  <p>I've never used Extension Methods before, so does this code appear to accomplish what I want? The code "works", but I'm looking for another set of eyes to make sure I'm not ending up with parameters that will force re-evaluation of an SQL Server execution plan.</p>
  
  <p><strong>EDIT: I had to actually add the parameter to the "params" collection, so I've updated the code. Now it "works" ;-)</strong></p>
  
  <pre><code>Imports System.Runtime.CompilerServices
  
  Public Module AdoParameterExtensions
  
      &lt;System.Runtime.CompilerServices.Extension()&gt; _
      Public Sub AddWithNumericValue(ByVal params As System.Data.SqlClient.SqlParameterCollection, ByVal parameterName As String, ByVal parameterType As SqlDbType, ByVal value As Object)
  
          Dim newParam As New System.Data.SqlClient.SqlParameter
  
          With newParam
  
              .ParameterName = parameterName
              .SqlDbType = parameterType
              .Value = value
  
          End With
  
          params.Add(newParam)
  
      End Sub
  
      &lt;System.Runtime.CompilerServices.Extension()&gt; _
      Public Sub AddWithStringValue(ByVal params As System.Data.SqlClient.SqlParameterCollection, ByVal parameterName As String, ByVal parameterType As SqlDbType, ByVal size As Integer, ByVal value As Object)
  
          Dim newParam As New System.Data.SqlClient.SqlParameter
  
          With newParam
  
              .ParameterName = parameterName
              .SqlDbType = parameterType
              .Size = size
              .Value = value
  
          End With
  
          params.Add(newParam)
  
      End Sub
  
  End Module
  </code></pre>
  
  <p>Thanks for your feedback.</p>