anthonyandroid
12/17/2016, 1:46 PMdoIf
extension method for my View
. What I want is:
- First check if the View is target ViewType
- If so, do the things.
And I try to do it, come out with these code:
fun View.doIf(shouldDo: Boolean, init: Unit) {
if(shouldDo) init
}
This can work but it doesn't look quite perfect... cause every time I am using this extension, I need to write the code like this:
a.doIf(a is SomeViewType, (a as SomeViewType).doSomething)
Any idea how to auto convert a
to SomeViewType
? I am thinking I might have something wrong in my extension method...