Skip to content

Editing BiDictionaries a little unsafe #84

@charlesroddie

Description

@charlesroddie

The following code occasionally causes a crash on Android.

do  let colDict = CSharpMath.Structures.Color.PredefinedColors
colDict.Remove("green",CSharpMath.Structures.Color(0uy,128uy,0uy)) |> ignore
colDict.Add("green",CSharpMath.Structures.Color(130uy,212uy,20uy))

Error report from @kevcrooks

The exception is System.ArgumentException: Duplicate second Parameter name: second
My thought is perhaps this line of code is being run twice, if a user has closed and re-opened the app or something.

This is fixed by changing to:

do  let colDict = CSharpMath.Structures.Color.PredefinedColors
colDict.Remove("green",CSharpMath.Structures.Color(colDict.["green"]) |> ignore
colDict.Add("green",CSharpMath.Structures.Color(130uy,212uy,20uy))

But it would be better for .Remove in a BiDictionary<'A,'B> only to take one argument which would increase safety, and also for .Add not to throw exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions