reflection, inho, has always been the sign of a bad idea. Reflection .. is
slow and cumbersome and (generally, yes I'm aware of the exceptions) should
NEVER make it to production code.

I would offer up the IS operator (though slightly expensive, it's not bad
compared to reflection) and then do your logic there.

>From what it looks like you are using different listviews based on the
android level, this would let you determine what object was passed in and
then you can grab the property you need.



http://msdn.microsoft.com/en-us/library/scekt9xw%28v=vs.71%29.aspx

On Tue, Aug 14, 2012 at 10:18 AM, Jonathan Pryor <j...@xamarin.com> wrote:

> On Aug 14, 2012, at 6:15 AM, Goncalo Oliveira <gonc...@minkan.net> wrote:
> > The thing is... this is kind of unusable. The whole reason I'm using
> reflection is because I don't know which properties I might need.
>
> I don't understand this; why is Reflection preferable to using type
> checking? Why wouldn't you know which properties you need?
>
>         static int GetSelectedItemPosition (object value)
>         {
>                 var v = value as AdapterView;   // base class of Spinner
>                 if (s != null)
>                         return v.SelectedItemPosition;
>                 var a = value as ListActivity;
>                 if (a != null)
>                         return a.SelectedItemPosition;
> #if __ANDROID_11__
>                 var w = value as ListPopupWindow;
>                 if (w != null)
>                         return w.SelectedItemPosition;
>                 var f = value as ListFragment;
>                 if (f != null)
>                         return f.SelectedItemPosition;
> #endif  // __ANDROID_11__
>                 // check other types as necessary
>                 throw new NotSupportedException ("Cannot get
> SelectedItemPosition from " + value.GetType ().FullName);
>         }
>
>  - Jon
>
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Extreme Knowledge is not something for which he programs a computer but for
which his computer is programming him.

-Wozniak


   - if my programming advice has helped you, feel free to donate to :
<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>

<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>
<https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYUXV2PG88YQQ>
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to