Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and copyDynamicProperties #27

Merged
merged 5 commits into from
Aug 30, 2024
Merged

Fixes and copyDynamicProperties #27

merged 5 commits into from
Aug 30, 2024

Conversation

HLWeil
Copy link
Member

@HLWeil HLWeil commented Aug 29, 2024

#26

@HLWeil HLWeil marked this pull request as ready for review August 29, 2024 14:06
@@ -21,11 +21,8 @@ type DynamicObj() =
/// Gets property value
member this.TryGetValue name =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix #25 ? If so, please add a regression test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not related

/// Sets property value, creating a new property if none exists
member this.SetValue (name,value) = // private
// first check to see if there's a native property to set

match ReflectionUtils.tryGetPropertyInfo this name with
match ReflectionUtils.tryGetStaticPropertyInfo this name with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you have this.TryGetStaticPropertyInfo, can you use it here instead of an external module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What module do you mean?

Copy link
Member

@kMutagene kMutagene Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReflectionUtils.tryGetStaticPropertyInfo is used although a method with the exact same name exists on the class. On other members, you used the instance method instead of the functions from ReflectionUtils

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, you used this.TryGetPropertyInfo in the Remove method instead of ReflectionUtils.tryGetPropertyInfo

@@ -137,6 +164,23 @@ type DynamicObj() =
#endif
|> Seq.filter (fun kv -> kv.Key.ToLower() <> "properties")

/// Copies all dynamic members of the DynamicObj to the target DynamicObj.
member this.CopyDynamicPropertiesTo(target:#DynamicObj, ?overWrite) =
let overWrite = Option.defaultValue false overWrite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also defaultArg, i vaguely remember that being better to use in these scenarios, but i do not remember why. Your call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Fable you mean?

Copy link
Member

@kMutagene kMutagene Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no i mean in general for determining default args for optional arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it doesn't matter.

In cases where the default expression is computationally expensive, it's worth to switch to an explicit match. But not sure whether Option.defaultValue and defaultArg even have different implementations.

@HLWeil HLWeil merged commit 4c53824 into main Aug 30, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants