public void ConfigureControl(Control control, Object dataItem) { FieldInfo[] fis = control.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fi in fis) { ConnectionAttribute a = (ConnectionAttribute)Attribute.GetCustomAttribute(fi, typeof(ConnectionAttribute)); if (a != null && a.ConnectedType.Equals(dataItem.GetType())) { Control c = (Control)fi.GetValue(control); if ((c == null) || (!c.Visible && !a.CopyOnInvisible()) || (!c.Enabled && !a.CopyOnDisabled())) { continue; } else { CopyProperty(dataItem, a, c); } } } }
public T CreateDataItem <T>(Control control) where T : new() { FieldInfo[] fis = control.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); T t = new T(); foreach (FieldInfo fi in fis) { ConnectionAttribute a = (ConnectionAttribute)Attribute.GetCustomAttribute(fi, typeof(ConnectionAttribute)); if (a != null && a.ConnectedType.Equals(t.GetType())) { Control c = (Control)fi.GetValue(control); if ((c == null) || (!c.Visible && !a.CopyOnInvisible()) || (!c.Enabled && !a.CopyOnDisabled())) { if (a.DefaultValueProvider != null) { CopyDefaultValue <T>(t, a); } } else { CopyProperty <T>(t, a, c); } } } return(t); }