public MyViewController(DateTimeElement container) { this.container = container; }
void Populate (object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance; if (Attribute.GetCustomAttribute(o.GetType (), typeof(SkipNonPublicAttribute)) == null) flags |= BindingFlags.NonPublic; var members = o.GetType ().GetMembers (flags); Section section = null; foreach (var mi in members){ Type mType = GetTypeForMember (mi); if (mType == null) continue; string caption = null; object [] attrs = mi.GetCustomAttributes (false); bool skip = false; foreach (var attr in attrs){ if (attr is SkipAttribute) skip = true; if (attr is CaptionAttribute) caption = ((CaptionAttribute) attr).Caption; else if (attr is SectionAttribute){ if (section != null) root.Add (section); var sa = attr as SectionAttribute; section = new Section (sa.Caption, sa.Footer); } } if (skip) continue; if (caption == null) caption = MakeCaption (mi.Name); if (section == null) section = new Section (); Element element = null; if (mType == typeof (string)){ PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; NSAction invoke = null; bool multi = false; foreach (object attr in attrs){ if (attr is PasswordAttribute) pa = attr as PasswordAttribute; else if (attr is EntryAttribute) ea = attr as EntryAttribute; else if (attr is MultilineAttribute) multi = true; else if (attr is HtmlAttribute) html = attr; else if (attr is AlignmentAttribute) align = attr as AlignmentAttribute; if (attr is OnTapAttribute){ string mname = ((OnTapAttribute) attr).Method; if (callbacks == null){ throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType ().GetMethod (mname); if (method == null) throw new Exception ("Did not find method " + mname); invoke = delegate { method.Invoke (method.IsStatic ? null : callbacks, new object [0]); }; } } string value = (string) GetValue (mi, o); if (pa != null) element = new EntryElement (caption, pa.Placeholder, value, true); else if (ea != null) element = new EntryElement (caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType }; else if (multi) element = new MultilineElement (caption, value); else if (html != null) element = new HtmlElement (caption, value); else { var selement = new StringElement (caption, value); element = selement; if (align != null) selement.Alignment = align.Alignment; } if (invoke != null) ((StringElement) element).Tapped += invoke; } else if (mType == typeof (float)){ var floatElement = new FloatElement (null, null, (float) GetValue (mi, o)); floatElement.Caption = caption; element = floatElement; foreach (object attr in attrs){ if (attr is RangeAttribute){ var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof (bool)){ bool checkbox = false; foreach (object attr in attrs){ if (attr is CheckboxAttribute) checkbox = true; } if (checkbox) element = new CheckboxElement (caption, (bool) GetValue (mi, o)); else element = new BooleanElement (caption, (bool) GetValue (mi, o)); } else if (mType == typeof (DateTime)){ var dateTime = (DateTime) GetValue (mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs){ if (attr is DateAttribute) asDate = true; else if (attr is TimeAttribute) asTime = true; } if (asDate) element = new DateElement (caption, dateTime); else if (asTime) element = new TimeElement (caption, dateTime); else element = new DateTimeElement (caption, dateTime); } else if (mType.IsEnum){ var csection = new Section (); ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){ ulong v = Convert.ToUInt64 (GetValue (fi, null)); if (v == evalue) selected = idx; csection.Add (new RadioElement (MakeCaption (fi.Name))); idx++; } element = new RootElement (caption, new RadioGroup (null, selected)) { csection }; } else if (mType == typeof (UIImage)){ element = new ImageElement ((UIImage) GetValue (mi, o)); } else if (typeof (System.Collections.IEnumerable).IsAssignableFrom (mType)){ var csection = new Section (); int count = 0; if (last_radio_index == null) throw new Exception ("IEnumerable found, but no previous int found"); foreach (var e in (IEnumerable) GetValue (mi, o)){ csection.Add (new RadioElement (e.ToString ())); count++; } int selected = (int) GetValue (last_radio_index, o); if (selected >= count || selected < 0) selected = 0; element = new RootElement (caption, new MemberRadioGroup (null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof (int) == mType){ foreach (object attr in attrs){ if (attr is RadioSelectionAttribute){ last_radio_index = mi; break; } } } else { var nested = GetValue (mi, o); if (nested != null){ var newRoot = new RootElement (caption); Populate (callbacks, nested, newRoot); element = newRoot; } } if (element == null) continue; section.Add (element); mappings [element] = new MemberAndInstance (mi, o); } root.Add (section); }
void Populate(object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; var members = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members) { Type mType = GetTypeForMember(mi); if (mType == null) { continue; } string caption = null; object [] attrs = mi.GetCustomAttributes(false); bool skip = false; foreach (var attr in attrs) { if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute) { skip = true; } else if (attr is CaptionAttribute) { caption = ((CaptionAttribute)attr).Caption; } else if (attr is SectionAttribute) { if (section != null) { root.Add(section); } var sa = attr as SectionAttribute; section = new Section(sa.Caption, sa.Footer); } } if (skip) { continue; } if (caption == null) { caption = MakeCaption(mi.Name); } if (section == null) { section = new Section(); } Element element = null; if (mType == typeof(string)) { PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; NSAction invoke = null; bool multi = false; foreach (object attr in attrs) { if (attr is PasswordAttribute) { pa = attr as PasswordAttribute; } else if (attr is EntryAttribute) { ea = attr as EntryAttribute; } else if (attr is MultilineAttribute) { multi = true; } else if (attr is HtmlAttribute) { html = attr; } else if (attr is AlignmentAttribute) { align = attr as AlignmentAttribute; } if (attr is OnTapAttribute) { string mname = ((OnTapAttribute)attr).Method; if (callbacks == null) { throw new Exception("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType().GetMethod(mname); if (method == null) { throw new Exception("Did not find method " + mname); } invoke = delegate { method.Invoke(method.IsStatic ? null : callbacks, new object [0]); }; } } string value = (string)GetValue(mi, o); if (pa != null) { element = new EntryElement(caption, pa.Placeholder, value, true); } else if (ea != null) { element = new EntryElement(caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType, AutocapitalizationType = ea.AutocapitalizationType, AutocorrectionType = ea.AutocorrectionType, ClearButtonMode = ea.ClearButtonMode } } ; else if (multi) { element = new MultilineElement(caption, value); } else if (html != null) { element = new HtmlElement(caption, value); } else { var selement = new StringElement(caption, value); element = selement; if (align != null) { selement.Alignment = align.Alignment; } } if (invoke != null) { ((StringElement)element).Tapped += invoke; } } else if (mType == typeof(float)) { var floatElement = new FloatElement(null, null, (float)GetValue(mi, o)); floatElement.Caption = caption; element = floatElement; foreach (object attr in attrs) { if (attr is RangeAttribute) { var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof(bool)) { bool checkbox = false; foreach (object attr in attrs) { if (attr is CheckboxAttribute) { checkbox = true; } } if (checkbox) { element = new CheckboxElement(caption, (bool)GetValue(mi, o)); } else { element = new BooleanElement(caption, (bool)GetValue(mi, o)); } } else if (mType == typeof(DateTime)) { var dateTime = (DateTime)GetValue(mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs) { if (attr is DateAttribute) { asDate = true; } else if (attr is TimeAttribute) { asTime = true; } } if (asDate) { element = new DateElement(caption, dateTime); } else if (asTime) { element = new TimeElement(caption, dateTime); } else { element = new DateTimeElement(caption, dateTime); } } else if (mType.IsEnum) { var csection = new Section(); ulong evalue = Convert.ToUInt64(GetValue(mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static)) { ulong v = Convert.ToUInt64(GetValue(fi, null)); if (v == evalue) { selected = idx; } CaptionAttribute ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute; csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name))); idx++; } element = new RootElement(caption, new RadioGroup(null, selected)) { csection }; } else if (mType == typeof(UIImage)) { element = new ImageElement((UIImage)GetValue(mi, o)); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType)) { var csection = new Section(); int count = 0; if (last_radio_index == null) { throw new Exception("IEnumerable found, but no previous int found"); } foreach (var e in (IEnumerable)GetValue(mi, o)) { csection.Add(new RadioElement(e.ToString())); count++; } int selected = (int)GetValue(last_radio_index, o); if (selected >= count || selected < 0) { selected = 0; } element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof(int) == mType) { foreach (object attr in attrs) { if (attr is RadioSelectionAttribute) { last_radio_index = mi; break; } } } else { var nested = GetValue(mi, o); if (nested != null) { var newRoot = new RootElement(caption); Populate(callbacks, nested, newRoot); element = newRoot; } } if (element == null) { continue; } section.Add(element); mappings [element] = new MemberAndInstance(mi, o); } root.Add(section); }
public CalendarMonthViewController(DateTimeElement currentDate) { container = currentDate; CurrentDate = container.DateValue; }
private void BuildElementPropertyMap() { _ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, Element>>(); _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings)=> { Element element = null; var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>(); if (buttonAttribute != null) { element = new ButtonElement(caption) { BackgroundColor = buttonAttribute.BackgroundColor, TextColor = buttonAttribute.TextColor, Command = GetCommandForMember(dataContext, member) }; } return element; }); _ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, dataContext, bindings)=> { Element element = null; var mapAttribute = member.GetCustomAttribute<MapAttribute>(); var location = (CLLocationCoordinate2D)GetValue(member, dataContext); if (mapAttribute != null) element = new MapElement(mapAttribute.Caption, mapAttribute.Value, location); return element; }); _ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings)=> { Element element = null; var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>(); var entryAttribute = member.GetCustomAttribute<EntryAttribute>(); var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>(); var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>(); var alignmentAttribute = member.GetCustomAttribute<AlignmentAttribute>(); if (passwordAttribute != null) element = new EntryElement(caption, passwordAttribute.Placeholder, true); else if (entryAttribute != null) element = new EntryElement(caption, entryAttribute.Placeholder) { KeyboardType = entryAttribute.KeyboardType }; else if (multilineAttribute != null) element = new MultilineElement(caption); else if (htmlAttribute != null) { SetDefaultConverter(member, "Value", new UriConverter(), bindings); element = new HtmlElement(caption); } else { var selement = new StringElement(caption, (string)GetValue(member, dataContext)); if (alignmentAttribute != null) selement.Alignment = alignmentAttribute.Alignment; element = selement; } var tappable = element as ITappable; if (tappable != null) ((ITappable)element).Command = GetCommandForMember(dataContext, member); return element; }); _ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings)=> { Element element = null; var rangeAttribute = member.GetCustomAttribute<RangeAttribute>(); if (rangeAttribute != null) { var floatElement = new FloatElement() { }; floatElement.Caption = caption; element = floatElement; floatElement.MinValue = rangeAttribute.Low; floatElement.MaxValue = rangeAttribute.High; floatElement.ShowCaption = rangeAttribute.ShowCaption; } else { var entryAttribute = member.GetCustomAttribute<EntryAttribute>(); var placeholder = ""; var keyboardType = UIKeyboardType.NumberPad; if(entryAttribute != null) { placeholder = entryAttribute.Placeholder; if(entryAttribute.KeyboardType != UIKeyboardType.Default) keyboardType = entryAttribute.KeyboardType; } element = new EntryElement(caption, placeholder, "") { KeyboardType = keyboardType }; } return element; }); _ElementPropertyMap.Add(typeof(Uri), (member, caption, dataContext, bindings)=> { return new HtmlElement(caption, (Uri)GetValue(member, dataContext)); }); _ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings)=> { Element element = null; var checkboxAttribute = member.GetCustomAttribute<CheckboxAttribute>(); if (checkboxAttribute != null) element = new CheckboxElement(caption) { }; else element = new BooleanElement(caption) { }; return element; }); _ElementPropertyMap.Add(typeof(DateTime), (member, caption, dataContext, bindings)=> { Element element = null; var dateAttribute = member.GetCustomAttribute<DateAttribute>(); var timeAttribute = member.GetCustomAttribute<TimeAttribute>(); if(dateAttribute != null) element = new DateElement(caption); else if (timeAttribute != null) element = new TimeElement(caption); else element = new DateTimeElement(caption); return element; }); _ElementPropertyMap.Add(typeof(UIImage),(member, caption, dataContext, bindings)=> { return new ImageElement(); }); _ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings)=> { return new StringElement(caption) { Value = GetValue(member, dataContext).ToString() }; }); }
private void BuildElementPropertyMap() { _ElementPropertyMap = new Dictionary <Type, Func <MemberInfo, string, object, List <Binding>, Element> >(); _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings) => { Element element = null; var buttonAttribute = member.GetCustomAttribute <ButtonAttribute>(); if (buttonAttribute != null) { element = new ButtonElement(caption) { BackgroundColor = buttonAttribute.BackgroundColor, TextColor = buttonAttribute.TextColor, Command = GetCommandForMember(dataContext, member) }; } return(element); }); _ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, dataContext, bindings) => { Element element = null; var mapAttribute = member.GetCustomAttribute <MapAttribute>(); var location = (CLLocationCoordinate2D)GetValue(member, dataContext); if (mapAttribute != null) { element = new MapElement(mapAttribute.Caption, mapAttribute.Value, location); } return(element); }); _ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings) => { Element element = null; var passwordAttribute = member.GetCustomAttribute <PasswordAttribute>(); var entryAttribute = member.GetCustomAttribute <EntryAttribute>(); var multilineAttribute = member.GetCustomAttribute <MultilineAttribute>(); var htmlAttribute = member.GetCustomAttribute <HtmlAttribute>(); var alignmentAttribute = member.GetCustomAttribute <AlignmentAttribute>(); if (passwordAttribute != null) { element = new EntryElement(caption, passwordAttribute.Placeholder, true); } else if (entryAttribute != null) { element = new EntryElement(caption, entryAttribute.Placeholder) { KeyboardType = entryAttribute.KeyboardType } } ; else if (multilineAttribute != null) { element = new MultilineElement(caption); } else if (htmlAttribute != null) { SetDefaultConverter(member, "Value", new UriConverter(), bindings); element = new HtmlElement(caption); } else { var selement = new StringElement(caption, (string)GetValue(member, dataContext)); if (alignmentAttribute != null) { selement.Alignment = alignmentAttribute.Alignment; } element = selement; } var tappable = element as ITappable; if (tappable != null) { ((ITappable)element).Command = GetCommandForMember(dataContext, member); } return(element); }); _ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings) => { Element element = null; var rangeAttribute = member.GetCustomAttribute <RangeAttribute>(); if (rangeAttribute != null) { var floatElement = new FloatElement() { }; floatElement.Caption = caption; element = floatElement; floatElement.MinValue = rangeAttribute.Low; floatElement.MaxValue = rangeAttribute.High; floatElement.ShowCaption = rangeAttribute.ShowCaption; } else { var entryAttribute = member.GetCustomAttribute <EntryAttribute>(); var placeholder = ""; var keyboardType = UIKeyboardType.NumberPad; if (entryAttribute != null) { placeholder = entryAttribute.Placeholder; if (entryAttribute.KeyboardType != UIKeyboardType.Default) { keyboardType = entryAttribute.KeyboardType; } } element = new EntryElement(caption, placeholder, "") { KeyboardType = keyboardType }; } return(element); }); _ElementPropertyMap.Add(typeof(Uri), (member, caption, dataContext, bindings) => { return(new HtmlElement(caption, (Uri)GetValue(member, dataContext))); }); _ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings) => { Element element = null; var checkboxAttribute = member.GetCustomAttribute <CheckboxAttribute>(); if (checkboxAttribute != null) { element = new CheckboxElement(caption) { } } ; else { element = new BooleanElement(caption) { } }; return(element); }); _ElementPropertyMap.Add(typeof(DateTime), (member, caption, dataContext, bindings) => { Element element = null; var dateAttribute = member.GetCustomAttribute <DateAttribute>(); var timeAttribute = member.GetCustomAttribute <TimeAttribute>(); if (dateAttribute != null) { element = new DateElement(caption); } else if (timeAttribute != null) { element = new TimeElement(caption); } else { element = new DateTimeElement(caption); } return(element); }); _ElementPropertyMap.Add(typeof(UIImage), (member, caption, dataContext, bindings) => { return(new ImageElement()); }); _ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings) => { return(new StringElement(caption) { Value = GetValue(member, dataContext).ToString() }); }); }
public CalloutViewCtrl () : base(null) { this.CentersCheck = new CheckboxElement[Centers.Length]; for (int i = 0; i < Centers.Length; i++) { var tmp = new CheckboxElement (Centers[i]); this.CentersCheck [i] = tmp; } this.FirstName = new EntryElement ("First Name", "Rocky", KeyStore.Get ("FirstName")) { TextAlignment = UITextAlignment.Right }; this.LastName = new EntryElement ("Last Name", "D. Bull", KeyStore.Get ("LastName")) { TextAlignment = UITextAlignment.Right }; this.Email = new EntryElement ("E-Mail", "*****@*****.**", KeyStore.Get ("Email")) { TextAlignment = UITextAlignment.Right, KeyboardType = UIKeyboardType.EmailAddress }; OptionGroup = new RadioGroup ("type", 0); Callout = new RadioElement ("Call-Out", "type"); Inlate = new RadioElement ("In Late", "type"); StartDate = new DateElement ("Out On", DateTime.Today) { Alignment = UITextAlignment.Right }; MultipleDays = new BooleanElement ("Out Multiple Days", false); EndDate = new DateElement ("Back On", DateTime.Today.AddDays (1)) { Alignment = UITextAlignment.Right }; WhenInDate = new DateTimeElement ("Will Be In", DateTime.Today.AddHours (12)) { Alignment = UITextAlignment.Right }; Explaination = new EntryElement ("Explaination", "reasons.", null) { TextAlignment = UITextAlignment.Right }; Section Name = new Section () { FirstName, LastName, Email }; Section Options = new Section () { Callout, Inlate }; Section CalloutDates = new Section () { StartDate, MultipleDays }; MultipleDays.ValueChanged += (sender, e) => { if (MultipleDays.Value) { CalloutDates.Add(EndDate); } else { CalloutDates.Remove(EndDate); } }; Section LateDay = new Section () { WhenInDate }; Callout.Tapped += delegate { this.Root.RemoveAt(2); this.Root.Insert(2, CalloutDates); }; Inlate.Tapped += delegate { this.Root.RemoveAt(2); this.Root.Insert(2, LateDay); }; this.Submit = new StringElement ("Submit") { Alignment = UITextAlignment.Center }; this.Root = new RootElement ("Call-Out", OptionGroup) { Name, Options, CalloutDates, new Section("Centers") { this.CentersCheck }, new Section() { Explaination }, new Section() { Submit } }; this.Submit.Tapped += Submit_Tapped; this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Cancel, delegate { this.NavigationController.PopViewController(true); }); }
void Populate (object callbacks, object o, RootElement root) { var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members){ Type mType = GetTypeForMember (mi); if (mType == null) continue; string caption = null; object [] attrs = mi.GetCustomAttributes (false); foreach (var attr in attrs){ if (attr is CaptionAttribute) caption = ((CaptionAttribute) attr).Caption; else if (attr is SectionAttribute){ if (section != null) Root.Add (section); var sa = attr as SectionAttribute; section = new Section (sa.Caption, sa.Footer); } } if (caption == null) caption = MakeCaption (mi.Name); if (section == null) section = new Section (); Element element = null; if (mType == typeof (string)){ PasswordAttribute pa = null; EntryAttribute ea = null; NSAction invoke = null; bool multi = false; foreach (object attr in attrs){ if (attr is PasswordAttribute) pa = attr as PasswordAttribute; else if (attr is EntryAttribute) ea = attr as EntryAttribute; else if (attr is MultilineAttribute) multi = true; if (attr is OnTapAttribute){ string mname = ((OnTapAttribute) attr).Method; if (callbacks == null){ throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType ().GetMethod (mname); if (method == null) throw new Exception ("Did not find method " + mname); invoke = delegate { method.Invoke (method.IsStatic ? null : callbacks, new object [0]); }; } } string value = (string) GetValue (mi, o); if (pa != null) element = new EntryElement (caption, pa.Placeholder, value, true); else if (ea != null) element = new EntryElement (caption, ea.Placeholder, value); else if (multi) element = new MultilineElement (caption, value); else element = new StringElement (caption, value); if (invoke != null) ((StringElement) element).Tapped += invoke; } else if (mType == typeof (float)){ var floatElement = new FloatElement (null, null, (float) GetValue (mi, o)); element = floatElement; foreach (object attr in attrs){ if (attr is RangeAttribute){ var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; } } } else if (mType == typeof (bool)){ bool checkbox = false; foreach (object attr in attrs){ if (attr is CheckboxAttribute) checkbox = true; } if (checkbox) element = new CheckboxElement (caption, (bool) GetValue (mi, o)); else element = new BooleanElement (caption, (bool) GetValue (mi, o)); } else if (mType == typeof (DateTime)){ var dateTime = (DateTime) GetValue (mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs){ if (attr is DateAttribute) asDate = true; else if (attr is TimeAttribute) asTime = true; } if (asDate) element = new DateElement (caption, dateTime); else if (asTime) element = new TimeElement (caption, dateTime); else element = new DateTimeElement (caption, dateTime); } else if (mType.IsEnum){ var csection = new Section (); ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){ ulong v = Convert.ToUInt64 (GetValue (fi, null)); if (v == evalue) selected = idx; csection.Add (new RadioElement (MakeCaption (fi.Name))); idx++; } element = new RootElement (caption, new RadioGroup (null, selected)) { csection }; } else if (mType == typeof (UIImage)){ element = new ImageElement ((UIImage) GetValue (mi, o)); } else { var nested = GetValue (mi, o); if (nested != null){ var newRoot = new RootElement (caption); Populate (callbacks, nested, newRoot); element = newRoot; } } if (element == null) continue; section.Add (element); mappings [element] = new MemberAndInstance (mi, o); } root.Add (section); }
private void DEle_DateSelected(DateTimeElement obj) { throw new NotImplementedException(); }
public BindingContext (object o, string title) { mappings = new Dictionary<Element,MemberAndInstance> (); var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Root = new RootElement (title); Section section = null; foreach (var mi in members){ Type mType = GetTypeForMember (mi); if (mType == null) continue; string caption = null; object [] attrs = mi.GetCustomAttributes (false); foreach (var attr in attrs){ if (attr is CaptionAttribute) caption = ((CaptionAttribute) attr).Caption; else if (attr is SectionAttribute){ if (section != null) Root.Add (section); var sa = attr as SectionAttribute; section = new Section (sa.Caption, sa.Footer); } } if (caption == null) caption = MakeCaption (mi.Name); if (section == null) section = new Section (); Element element = null; if (mType == typeof (string)){ PasswordAttribute pa = null; EntryAttribute ea = null; foreach (object attr in attrs){ if (attr is PasswordAttribute) pa = attr as PasswordAttribute; else if (attr is EntryAttribute) ea = attr as EntryAttribute; } if (pa != null) element = new EntryElement (caption, pa.Placeholder, (string) GetValue (mi, o), true); else if (ea != null) element = new EntryElement (caption, ea.Placeholder, (string) GetValue (mi, o)); else element = new StringElement (caption, (string) GetValue (mi, o)); } else if (mType == typeof (float)){ element = new FloatElement (null, null, (float) GetValue (mi, o)); } else if (mType == typeof (bool)){ element = new BooleanElement (caption, (bool) GetValue (mi, o)); } else if (mType == typeof (DateTime)){ var dateTime = (DateTime) GetValue (mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs){ if (attr is DateAttribute) asDate = true; else if (attr is TimeAttribute) asTime = true; } if (asDate) element = new DateElement (caption, dateTime); else if (asTime) element = new TimeElement (caption, dateTime); else element = new DateTimeElement (caption, dateTime); } else if (mType.IsEnum){ var csection = new Section (); ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){ ulong v = Convert.ToUInt64 (GetValue (fi, null)); if (v == evalue) selected = idx; csection.Add (new RadioElement (fi.Name)); idx++; } element = new RootElement (caption, new RadioGroup (null, selected)) { csection }; } if (element == null) continue; section.Add (element); mappings [element] = new MemberAndInstance (mi, o); } Root.Add (section); }