title: How to create optional arguments in Visual Basic generated through CodeDom?
body: <p>This is a cousin of the question "<a href="https://stackoverflow.com/questions/4740727/can-codedom-create-optional-arguments-when-generating-a-c-sharp-method?rq=1">Can CodeDom create optional arguments when generating a c# method?</a>"</p>
  
  <p>And I tried the answer given <a href="https://stackoverflow.com/a/4740759/474683">there</a>.</p>
  
  <p>Still, when I attempt to compile, I get the following error:</p>
  
  <blockquote>
    <p>error BC30455: Argument not specified for parameter 'optionalParam' of 'Public Function Bar(optionalParam As Integer) As Integer</p>
  </blockquote>
  
  <p>I've distilled this down to the Visual Basic Compiler not supporting either OptionalAttribute, DefaultParameterValueAttribute, or both.</p>
  
  <p>Here's the distilled code I'm compiling:</p>
  
  <pre><code>Imports System.Runtime.InteropServices
  
  Namespace SSI.RuntimeGenerated.FunctionsNamespace
      Public Class Functions
          Public Function Foo() As Integer
  
              return Bar()
  
          End Function
  
          Public Function Bar( _
              &lt;[Optional], DefaultParameterValue(1)&gt; _
              ByVal optionalParam As Integer) _
                  As Integer
  
              return optionalParam
  
          End Function
  
      End Class
  End Namespace
  </code></pre>
  
  <p>Compiling this with the following command:</p>
  
  <pre><code>"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:library /out:foobar.dll foobar.vb /langversion:11
  </code></pre>
  
  <p>Produces the following output:</p>
  
  <pre><code>Microsoft (R) Visual Basic Compiler version 11.0.50709.17929
  Copyright (c) Microsoft Corporation All rights reserved.
  
  C:\&lt;snip&gt;\foobar.vb : error BC30455: Argument not specified for parameter
  'optionalParam' of 'Public Function Bar(optionalParam As Integer) As Integer'.
              return Bar()
                     ~~~~~
  </code></pre>
  
  <p>If I change the method signature manually to be </p>
  
  <pre><code>Public Function Bar(Optional ByVal optionalParam As Integer) As Integer
  </code></pre>
  
  <p>then it compiles just fine.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>How to create optional arguments in Visual Basic generated through CodeDom?</li>
  <li>Does vbc even support use of OptionalAttribute and/or DefaultParameterValueAttribute?</li>
  <li>If vbc doesn't support those attributes, is there any possible way to create Optional arguments without resorting to using a CodeSnippetStatement?</li>
  <li>If there's no other way, then is it possible to salvage other work I've done with CodeDom so I don't end up having to pretty much generate my methods by hand? Do I have to pretty much build the rest by hand inside a CodeSnippetTypeMember? Would even <em>that</em> work?</li>
  </ol>