@@ -23,7 +23,6 @@ type DynamicObj() =
2323 // first check the Properties collection for member
2424 this.TryGetPropertyInfo( name)
2525 |> Option.map ( fun pi -> pi.GetValue( this))
26-
2726
2827 member this.GetValue ( name ) =
2928 this.TryGetValue( name) .Value
@@ -68,7 +67,7 @@ type DynamicObj() =
6867 match this.TryGetStaticPropertyInfo name with
6968 | Some pi -> Some pi
7069 | None -> this.TryGetDynamicPropertyInfo name
71-
70+
7271 /// Sets property value, creating a new property if none exists
7372 member this.SetValue ( name , value ) = // private
7473 // first check to see if there's a native property to set
@@ -99,7 +98,6 @@ type DynamicObj() =
9998 | Some _ -> failwith $" Cannot remove value for static, immutable property \" {name}\" "
10099 | None -> ()
101100
102-
103101 member this.GetPropertyHelpers ( includeInstanceProperties ) =
104102 #if FABLE_ COMPILER_ JAVASCRIPT || FABLE_ COMPILER_ TYPESCRIPT
105103 FableJS.getPropertyHelpers this
@@ -166,6 +164,23 @@ type DynamicObj() =
166164 #endif
167165 |> Seq.filter ( fun kv -> kv.Key.ToLower() <> " properties" )
168166
167+ /// Copies all dynamic members of the DynamicObj to the target DynamicObj.
168+ member this.CopyDynamicPropertiesTo ( target : #DynamicObj , ? overWrite ) =
169+ let overWrite = Option.defaultValue false overWrite
170+ this.GetProperties( false )
171+ |> Seq.iter ( fun kv ->
172+ match target.TryGetPropertyInfo kv.Key with
173+ | Some pi when overWrite -> pi.SetValue target kv.Value
174+ | Some _ -> failwith $" Property \" {kv.Key}\" already exists on target object and overWrite was not set to true."
175+ | None -> target.SetValue( kv.Key, kv.Value)
176+ )
177+
178+ /// Returns a new DynamicObj with only the dynamic properties of the original DynamicObj (sans instance properties).
179+ member this.CopyDynamicProperties () =
180+ let target = DynamicObj()
181+ this.CopyDynamicPropertiesTo( target)
182+ target
183+
169184 member this.GetPropertyNames ( includeInstanceProperties ) =
170185 this.GetProperties( includeInstanceProperties)
171186 |> Seq.map ( fun kv -> kv.Key)
0 commit comments