C# object initialization syntax in F#

后端 未结 3 763
攒了一身酷
攒了一身酷 2021-01-17 11:12

Please note: this question is not the same as this question.

I recently came across some C# syntax I hadn\'t previously encountered:

Is there any wa

3条回答
  •  鱼传尺愫
    2021-01-17 11:28

    Would it make sense to encapsulate the construction into a separate initializer function?

    let layerInit layer radius color offset opacity =
        do
           layer.ShadowRadius <- radius
           layer.ShadowColor <- color
           layer.ShadowOffset <- offset
           layer.ShadowOpacity <- opacity
        layer // I do this in case you want to use this fluently or pass in new Layer()
    

    Then use that in your code:

    let nameLabel = new UILabel ( TextColor = UIColor.White )
    layerInit nameLabel.Layer 3.0f UIColor.Black.CGColor new System.Drawing.SizeF(0.0f,1.0f) 0.5f |> ignore
    

提交回复
热议问题