|     You want to determine whether a connecting mobile device supports a certain technology or rendering method.     |          Technique   Mobile devices come in many forms, such as palmtops, dedicated Web devices, and cell phones. Because of the proliferation of all these devices, you occasionally have to tailor your site to work with a specific device. The  Device  property of the  MobilePage  class that your class derives from is a  MobileCapabilities  object. The  MobileCapabilities  class contains at least 72 different public properties that you can query to determine support for a certain technology. Listing 26.10 lists all the values for each property when a user connects to the page. To save your sanity , the code forgoes the painstakingly monotonous process of accessing each property individually. Rather, it uses reflection because that's what it's designed for, to dynamically retrieve all the public properties of the  MobileCapabilities  class. The final text is rendered onto a  TextView  mobile control.    Listing 26.10 Enumerating Device Properties   private void DeviceInformationForm_Load(object sender, System.EventArgs e) {     if( !Page.IsPostBack )     {         StringBuilder sb = new StringBuilder();         // for each public property         foreach( PropertyInfo prop in             Device.GetType().GetProperties(             BindingFlags.Instance  BindingFlags.Public) )         {             // only retrieve boolean properties             if( prop.PropertyType != typeof(bool))                 continue;             // print out property name and current value             if( prop.GetValue(Device, null) != null )                 tvDeviceInfo.Text += "<b>" +                 prop.Name + "</b> = <em>" +                 prop.GetValue( Device, null ).ToString()+ "</em><br>";         }     } }   Comments   If you run the mobile Web form containing the code in this recipe, you might be amazed. The .NET Compact Framework can determine several key pieces of information about a connecting mobile device that would be tremendously difficult and time-consuming to acquire without this support. The next recipe utilizes this information to support different rendering methods for specific classes of mobile devices.    |