/// <summary> /// Wires a control to a property. /// </summary> /// <param name="layoutHost">The layout view host.</param> /// <param name="resolveMembers">The resolve members.</param> public static void WireUpControls(this ILayoutViewHost layoutHost, ReactiveUI.ControlFetcherMixin.ResolveStrategy resolveMembers = ReactiveUI.ControlFetcherMixin.ResolveStrategy.Implicit) { var members = layoutHost.GetWireUpMembers(resolveMembers).ToList(); foreach (var member in members) { try { var view = layoutHost.View.GetControlInternal(member.GetResourceName()); member.SetValue(layoutHost, view); } catch (Exception ex) { throw new MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } } }
/// <summary> /// Wires a control to a property. /// </summary> /// <param name="view">The view.</param> /// <param name="resolveMembers">The resolve members.</param> public static void WireUpControls(this View view, ReactiveUI.ControlFetcherMixin.ResolveStrategy resolveMembers = ReactiveUI.ControlFetcherMixin.ResolveStrategy.Implicit) { var members = view.GetWireUpMembers(resolveMembers); foreach (var member in members) { try { // Find the android control with the same name var currentView = view.GetControlInternal(member.GetResourceName()); // Set the activity field's value to the view with that identifier member.SetValue(view, currentView); } catch (Exception ex) { throw new MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex); } } }
private static IEnumerable <PropertyInfo> GetWireUpMembers(this object @this, ReactiveUI.ControlFetcherMixin.ResolveStrategy resolveStrategy) { var members = @this.GetType().GetRuntimeProperties(); switch (resolveStrategy) { default: // Implicit matches the Default. return(members.Where(member => member.PropertyType.IsSubclassOf(typeof(View)) || member.GetCustomAttribute <WireUpResourceAttribute>(true) != null)); case ReactiveUI.ControlFetcherMixin.ResolveStrategy.ExplicitOptIn: return(members.Where(member => member.GetCustomAttribute <WireUpResourceAttribute>(true) != null)); case ReactiveUI.ControlFetcherMixin.ResolveStrategy.ExplicitOptOut: return(members.Where(member => typeof(View).IsAssignableFrom(member.PropertyType) && member.GetCustomAttribute <IgnoreResourceAttribute>(true) == null)); } }