What happens if the entity is not a polyline?
It could be a circle, line, text, mtext ......

I prefer to use selection sets. I can filter out what I don't want to work on while allowing the user to select whatever they want to. The drawing order messes up the selection when the entities cross. This way I know the properties are actually there, reduces the chance of the user selecting things that don't apply. Yeah I know it's a pain, but it keeps me out of trouble every once in a while.