protected override void Inject(object source, object target) { var targetProperties = target.GetProps().Cast <PropertyDescriptor>().AsQueryable(); foreach (PropertyDescriptor sourceProp in source.GetProps()) { var prop = sourceProp; if (targetProperties.Any(p => p.Name == prop.Name)) { //Exact match found targetProperties.First(p => p.Name == prop.Name).SetValue(target, SetValue(sourceProp.GetValue(source))); } else { //Fall back to UnflatLoopValueInjection var endpoints = UberFlatter.Unflat(sourceProp.Name, target, t => TypesMatch(prop.PropertyType, t)).ToList(); if (!endpoints.Any()) { continue; } var value = sourceProp.GetValue(source); if (!AllowSetValue(value)) { continue; } foreach (var endpoint in endpoints) { endpoint.Property.SetValue(endpoint.Component, SetValue(value)); } } } }
protected override void Inject(Control request, object target) { foreach (var control in request.GetChildControls()) { if (control.Text == string.Empty) { continue; } var endpoints = UberFlatter.Unflat(control.Name.RemovePrefix("txt"), target); if (endpoints.Count() == 0) { continue; } var desc = endpoints.First(); var c = TypeDescriptor.GetConverter(desc.Property.PropertyType); try { desc.Property.SetValue(desc.Component, c.ConvertFrom(control.Text)); } catch { //add form validaton and remove this } } }
public void UnflatTestIgnoreCase() { var u = new Unflat(); var es = UberFlatter.Unflat("foobarname", u, MatchIgnoreCase, StringComparison.OrdinalIgnoreCase); es.Count().IsEqualTo(2); UberFlatter.Unflat("foobarname", u, (upn, pi) => upn.Equals(pi.Name, StringComparison.OrdinalIgnoreCase), StringComparison.OrdinalIgnoreCase).Count().IsEqualTo(2); }
public void UnflatTest() { var u = new Unflat(); var es = UberFlatter.Unflat("FooBarName", u, Match); es.Count().IsEqualTo(2); UberFlatter.Unflat("FooBarName", u).Count().IsEqualTo(2); }
public void UnflatTestIgnoreCase() { var u = new Unflat(); var es = UberFlatter.Unflat("foobarname", u, t => t == typeof(string), StringComparison.OrdinalIgnoreCase); es.Count().IsEqualTo(2); UberFlatter.Unflat("foobarname", u, t => true, StringComparison.OrdinalIgnoreCase).Count().IsEqualTo(2); }
public void UnflatTest() { var u = new Unflat(); var es = UberFlatter.Unflat("FooBarName", u, t => t == typeof(string)); es.Count().IsEqualTo(2); UberFlatter.Unflat("FooBarName", u).Count().IsEqualTo(2); }
protected virtual void Execute(PropertyInfo sp, object source, object target) { if (sp.CanRead && sp.GetGetMethod() != null) { var endpoints = UberFlatter.Unflat(sp.Name, target, (upn, prop) => Match(upn, prop, sp), activator).ToArray(); foreach (var endpoint in endpoints) { SetValue(source, endpoint.Component, sp, endpoint.Property); } } }
protected override void Inject(Control request, object target) { foreach (DateTimePicker dt in request.GetChildControls <DateTimePicker>()) { var es = UberFlatter.Unflat(dt.Name.RemovePrefix("dt"), target); if (es.Count() == 0) { continue; } var desc = es.First(); desc.Property.SetValue(desc.Component, dt.Value); } }
protected override void Inject(object source, object target) { foreach (var sourceProp in source.GetType().GetProperties()) { var endpoints = UberFlatter.Unflat(sourceProp.Name, target); if (endpoints.Count() == 0) { continue; } var desc = endpoints.First(); var prop = sourceProp.GetValue(source); var result = prop == null ? prop : Convert.ChangeType(prop, desc.Property.PropertyType); desc.Property.SetValue(desc.Component, result); } }
public void Map(Type sourceType, object source, Type targetType, object target) { foreach (PropertyDescriptor propertyDescriptor in source.GetProps()) { PropertyDescriptor prop = propertyDescriptor; IEnumerable <PropertyWithComponent> source1 = UberFlatter.Unflat(propertyDescriptor.Name, target); if (source1.Count() != 0) { object sourcePropertyValue = propertyDescriptor.GetValue(source); foreach (PropertyWithComponent propertyWithComponent in source1) { object targetValue = GetTargetValue(propertyDescriptor.PropertyType, sourcePropertyValue, propertyWithComponent.Property.PropertyType); propertyWithComponent.Property.SetValue(propertyWithComponent.Component, targetValue); } } } }