Proposal: Chainable (postfix) casting
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Currently explicit casting can be made in prefix style:
`CType (obj, SomeType)`
which is uncomfortable in many situations:
```
CType(coll.First(Function (x) x.ID > 0), SomeType)
CType(CType(obj, SomeType).member, SomeOtherType)
```
This may be improved by adding virtual method, similar to ToString, but that exist only in language:
```
obj.ToType(SomeType)
coll.First(Function (x) x.ID > 0).ToType(SomeType)
obj.ToType(SomeType).member.ToType(SomeOtherType)
```
Such function may be currently created as extension method:
```
Public Function ToType(Of T1)(ByRef Src As Object) As T1
Return Src
End Function
```
but do not work for input casted to Object
```
Dim o As Object = ""
o.ToType(Of String).Length ' runtime error
```
and typing (Of ) with each call is redundant.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.