3 * Namespace : System.Web.UI.MobileControls
4 * Class : DeviceSpecificChoice
5 * Author : Gaurav Vaish
7 * Copyright : 2003 with Gaurav Vaish, and with
11 using System.ComponentModel;
12 using System.Collections;
13 using System.Collections.Specialized;
14 using System.Reflection;
16 using System.Web.Mobile;
18 namespace System.Web.UI.MobileControls
20 public class DeviceSpecificChoice : IParserAccessor,
23 private string argument;
24 private IDictionary contents;
25 private string filter;
26 private DeviceSpecific owner;
27 private IDictionary templates;
30 private static IComparer caseInsensitiveComparer
31 = new CaseInsensitiveComparer();
33 public DeviceSpecificChoice()
37 string IAttributeAccessor.GetAttribute(string key)
39 object val = Contents[key];
40 if(val != null && val is string)
43 throw new ArgumentException("DeviceSpecificChoice" +
44 "_PropetyNotAnAttribute");
47 void IAttributeAccessor.SetAttribute(string key, string value)
49 Contents[key] = value;
52 void IParserAccessor.AddParsedSubObject(object obj)
54 if(obj is DeviceSpecificChoiceTemplateContainer)
56 DeviceSpecificChoiceTemplateContainer ctr =
57 (DeviceSpecificChoiceTemplateContainer)obj;
58 Templates[ctr.Name] = ctr.Template;
62 public string Argument
70 this.argument = value;
74 public IDictionary Contents
78 if(this.contents == null)
80 this.contents = new ListDictionary(caseInsensitiveComparer);
98 public DeviceSpecific Owner
110 public IDictionary Templates
114 if(this.templates == null)
116 this.templates = new ListDictionary(caseInsensitiveComparer);
118 return this.templates;
122 internal void ApplyProperties()
124 IDictionaryEnumerator ide = Contents.GetEnumerator();
125 while(ide.MoveNext())
127 object owner = Owner.Owner;
128 string key = (string)ide.Key;
129 string value = (string)ide.Value;
130 if(key.ToLower() == "id")
133 throw new ArgumentException("DeviceSpecificChoice" +
134 "_InvalidPropertyOverride");
139 while((dash = key.IndexOf('-')) != -1)
141 string first = key.Substring(0, dash);
142 PropertyDescriptor pd =
143 TypeDescriptor.GetProperties(owner).Find(key, true);
147 throw new ArgumentException("DeviceSpecificChoice" +
148 "_OverridingPropertyNotFound");
150 owner = pd.GetValue(owner);
151 key = key.Substring(dash + 1);
153 if(!FindAndApplyProperty(owner, key, value) &&
154 !FindAndApplyEvent(owner, key, value))
156 if(owner is IAttributeAccessor)
158 ((IAttributeAccessor)owner).SetAttribute(key, value);
162 throw new ArgumentException("DeviceSpecificChoice" +
163 "_OverridingPropertyNotFound");
171 /// Returns false if not found or not applied
173 private bool FindAndApplyProperty(object parentObj, string key,
177 PropertyDescriptor pd =
178 TypeDescriptor.GetProperties(parentObj).Find(key, true);
181 if(pd.Attributes.Contains(
182 DesignerSerializationVisibilityAttribute.Hidden))
184 throw new ArgumentException("DeviceSpecificChoice" +
185 "_OverridingPropertyNotDeclarable");
187 throw new NotImplementedException();
191 private bool FindAndApplyEvent(object parentObj, string key,
197 if(key.ToLower().StartsWith("on"))
199 string eventName = key.Substring(2);
201 TypeDescriptor.GetEvents(parentObj).Find(key, true);
204 ed.AddEventHandler(parentObj,
205 Delegate.CreateDelegate(ed.EventType,
206 Owner.MobilePage, eventName));
213 private bool CheckOnPageEvaluator(MobileCapabilities capabilities,
214 out bool evaluatorResult)
216 boolr retVal = false;
217 evaluatorResult = false;
218 TemplateControl tc = Owner.ClosestTemplateControl;
219 // I have to get the method (MethodInfo?) and then invoke
220 // the method and send back the results of the method!
221 throw new NotImplementedException();
224 public bool HasTemplates
228 return (templates != null && templates.Count > 0);