我在父对象中有一个let handleNewEntry (model : Model) (msg : NewEntry) =
let form' =
match msg, model.form with
| NewOriginMerdEntry m, OriginMerd o -> handleNewOriginMerdEntry o m
| NewOriginMerdEntry m, _ -> failwithf "expected origin type got something else"
| NewDestMerdEntry m, DestMerd d -> handleNewDestMerdEntry d m
| NewDestMerdEntry m, _ -> failwithf "expected dest type got something else"
{model with form = form'}, Cmd.none
let handleNewOriginMerdEntry (formOpt : OriginMerdEntry option) (msg : NewOriginMerdEntry) =
let form = formOpt |> Option.defaultValue OriginMerd.New
let result =
match msg with
| AddOriginMerdID i -> {form with originMerdID = i}
| AddMerdNumber n -> {form with merdNumber = n}
| AddPD p -> {form with pD = p}
| AddAverageWeight w -> {form with averageWeight = w}
OriginMerd (Some result)
let handleNewDestMerdEntry (formOpt : DestMerdEntry option) (msg : NewDestMerdEntry) =
let form = formOpt |> Option.defaultValue DestMerd.New
let result =
match msg with
| AddDestMerdID i -> {form with destMerdID = i}
DestMerd (Some result)
属性,我需要更新此属性。
简单地分配一个新的List<MyObject> MyProperty { get; set; } = new List<MyObject>();
似乎可以正常工作,但是我不确定这是否是一种干净的方法-见下文:
List<MyObject>
或者,我可以遍历该属性的值,但这似乎是一个更麻烦的方法。
是否只是像上面显示的那样分配一个新的parentObject.MyProperty = newList; // newList is a List<MyObject> with new values in it
?
P.S。新的List<MyObject>
可能只包含其他值,也可能具有一组全新的值。