title: C# object initialization syntax in F#
body: <p>Please note: this question is <em>not</em> the same as <a href="https://stackoverflow.com/questions/371878/object-initialization-syntax">this</a> question.</p>
  
  <p>I recently came across some C# syntax I hadn't previously encountered:</p>
  
  <p>Is there any way to do this in F#?</p>
  
  <pre><code>class Two
  {
      public string Test { get; set; }
  }
  
  class One
  {
      public One()
      {
          TwoProperty = new Two();
      }
      public Two TwoProperty { get; private set; }
  }
  
  var test = new One(){ TwoProperty = { Test = "Test String" }};
  </code></pre>
  
  <p>(note the initialization of <code>TwoProperty</code> in the initializer when the setter is private - it is setting a property on the object stored in <code>TwoProperty</code>, but <em>NOT</em> storing a new instance of <code>Two</code> in the property)</p>
  
  <p>Edit:
  I recently came across some C# code in a constructor in monotouch like this:</p>
  
  <pre><code>nameLabel = new UILabel {
      TextColor = UIColor.White,
      Layer = {
          ShadowRadius = 3,
          ShadowColor = UIColor.Black.CGColor,
          ShadowOffset = new System.Drawing.SizeF(0,1f),
          ShadowOpacity = .5f
      }
  };
  </code></pre>
  
  <p>The best F# translation I could come up with was something like this:</p>
  
  <pre><code>let nameLabel = new UILabel ( TextColor = UIColor.White )
  do let layer = nameLabel.Layer
     layer.ShadowRadius &lt;- 3.0f
     layer.ShadowColor &lt;- UIColor.Black.CGColor
     layer.ShadowOffset &lt;- new System.Drawing.SizeF(0.0f,1.0f)
     layer.ShadowOpacity &lt;- 0.5f  
  </code></pre>
  
  <p>This isn't terrible, but it does have more noise with the repeated <code>layer</code> reference plus its more imperative and less declarative.</p>