title: Using Codedom to write VB.Net Properties
body: <p>Looking at the example code on <a href="http://msdn.microsoft.com/en-us/library/system.codedom.codepropertysetvaluereferenceexpression(loband).aspx" rel="nofollow noreferrer">MSDN</a>:</p>
  
  <p>This </p>
  
  <pre><code>    ' Declares a type.
      Dim type1 As New CodeTypeDeclaration("Type1")
  
      ' Declares a constructor.
      Dim constructor1 As New CodeConstructor
      constructor1.Attributes = MemberAttributes.Public
      type1.Members.Add(constructor1)
  
      ' Declares an integer field.
      Dim field1 As New CodeMemberField("System.Int32", "integerField")
      type1.Members.Add(field1)
  
      ' Declares a property.
      Dim property1 As New CodeMemberProperty
      property1.Name = "integerProperty"
      property1.Type = New CodeTypeReference(GetType(Integer))
      ' Declares a property get statement to return the value of the integer field.
      property1.GetStatements.Add(New CodeMethodReturnStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression, "integerField")))
      ' Declares a property set statement to set the value to the integer field.
      ' The CodePropertySetValueReferenceExpression represents the value argument passed to the property set statement.
      property1.SetStatements.Add(New CodeAssignStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression, "integerField"), New CodePropertySetValueReferenceExpression))
      type1.Members.Add(property1)
  
      Dim dump As New VBCodeProvider
      Dim gen As Compiler.ICodeGenerator = dump.CreateGenerator
      Dim opt As New Compiler.CodeGeneratorOptions
  
      gen.GenerateCodeFromType(type1, Console.Out, opt)
  </code></pre>
  
  <p>should generate</p>
  
  <pre><code>Public Class Type1
  
     Private integerField As Integer
  
     Public Sub New()
         MyBase.New()
     End Sub
  
     Private Property integerProperty() As Integer
         Get
             Return Me.integerField
         End Get
         Set(ByVal Value As Integer)
             Me.integerField = value
         End Set
     End Property
  End Class
  </code></pre>
  
  <p>But I'm not seeing it generate the parameter to the Set method, I.e. I get:</p>
  
  <pre><code>       Set
             Me.integerField = value
         End Set
  </code></pre>
  
  <p>Given that I already had to add in bits to the example code to actually name the property to match their example output, I suspect that there is a detail missing that is causing this, but I can't seem to track it down? Whilst the code compiles, I'm unable to use the properties without manually adding in the parameters, which defeats the purpose somewhat. Any idea what is missing?</p>