FindViewById<> CodeRush template

Here is an useful CodeRush editor template if you work with Mono For Android.


I use string fv as trigger. That makes binding variables/fields to Views a bit faster and with less typing.

Example, I’d type

someView = fv

then I’d press SPACE and I’d get an extended template

someView = FindViewById<|>(Resource.Id.|);|

Then I have to type just TextView, ENTER, someView, ENTER, ENTER and I’d get

someView = FindViewById<TextView>(Resource.Id.someView);| <- this is cursor

So instead of typing the whole enchillada I had to type only the letters in yellow.

someView = fvSPACEFindViewById<TextView>(Resource.Id.someView);

With Android these statements are quite common and thus the fv template spares me a lot of typing.

But hey it can get better. If stick to a naming convetion that variable name is the same as Id name + View suffix I can enhance the template, I will name it fvx.

«FieldStart(Name)»«Caret»«Link(viewName)»«BlockAnchor»«FieldEnd»View = FindViewById<«FieldStart»«FieldEnd»>(Resource.Id.«FieldStart»«Link(viewName)»«FieldEnd»);«Target()»

Note the «Link» directive that copies the typed text. And the typing result is

fvxSPACEsomeView = FindViewById<TextView>(Resource.Id.some);

Even better now, eh. The only further improvement is to deduce the variable type and type in TextView automatically. I have to investigate this option to refine the template even further.

You can use the two templates by simply creating them in CodeRush (DevExpress/Options/Editor/Selections/Templates) or you can import them (see attached file) into templates – right click in templates list and select Import Templates…


CSharp_Righthand_MonoForAndroid.xml (10.42 kb)