Menu

#20 Add a type detection for mungers (PutValue method)

v2.2
wont-fix
nobody
None
1
2014-09-29
2014-08-12
linken
No

I created an Custom Munger with type detection for my ObjectListview.
It's very basic, and I think you could do much better and integrate it.

Here it is :

Private Function TypedValue(ByVal InType As System.Type, ByVal Value As Object) As Object
Select Case InType
Case GetType(String)
Return Value.ToString
Case GetType(Single)
Return Convert_To_Sng(Value)
Case GetType(Double)
Return Convert_To_Dbl(Value)
Case Else
Return Value
End Select
End Function

and in the PutValue method

If (Me.resolvedPropertyInfo IsNot Nothing) Then >me.resolvedPropertyInfo.SetValue(target,
TypedValue(resolvedPropertyInfo.PropertyType, value),
Nothing)
Return True
End If

I added this because I wanted a default aspect putter, and using the SimpleMunger, I had errors with PutAspectByName method when I had single/double fields.

I Thought it could be useful !

1 Attachments

Discussion

  • Phillip Piper

    Phillip Piper - 2014-09-29

    The Munger can put any value that is implicitly convertable to the target type. For this to work, the value retrieved by the Munger must be convertable to the put target type.

    If you want more specific conversions, you can always install an aspect getter/putter.

     
  • Phillip Piper

    Phillip Piper - 2014-09-29
    • status: open --> wont-fix
     

Log in to post a comment.