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 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); }
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 FlatTestIgnoreCase() { var u = new Unflat() { Foo = new Foo1() { Bar = new Bar1() { Name = "dasName" } }, FooBar = new FooBar1() { Name = "uber" } }; var vv = UberFlatter.Flat("foobarname", u, MatchIgnoreCase, StringComparison.OrdinalIgnoreCase); vv.Count().IsEqualTo(2); var vvv = UberFlatter.Flat("foobarname", u, MatchIgnoreCase, StringComparison.OrdinalIgnoreCase); vvv.Count().IsEqualTo(2); }
public void FlatTest() { var u = new Unflat() { Foo = new Foo1() { Bar = new Bar1() { Name = "dasName" } }, FooBar = new FooBar1() { Name = "uber" } }; var vv = UberFlatter.Flat("FooBarName", u, Match); vv.Count().IsEqualTo(2); var vvv = UberFlatter.Flat("FooBarName", u); vvv.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(object source, ref Control target) { foreach (var txt in target.GetChildControls()) { var es = UberFlatter.Flat(txt.Name.RemovePrefix("txt"), source); if (es.Count() == 0) { continue; } var desc = es.First(); txt.Text = (desc.Property.GetValue(desc.Component) ?? "").ToString(); } }
protected override void Inject(object source, ref Control target) { foreach (DateTimePicker dt in target.GetChildControls <DateTimePicker>()) { var es = UberFlatter.Flat(dt.Name, source); if (es.Count() == 0) { continue; } var desc = es.First(); dt.Value = (DateTime)desc.Property.GetValue(desc.Component); } }
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 void Execute(PropertyInfo tp, object source, object target) { if (tp.CanWrite && tp.GetSetMethod() != null) { var endpoints = UberFlatter.Flat(tp.Name, source, (upn, prop) => Match(upn, prop, tp)).ToArray(); if (endpoints.Any()) { var endpoint = endpoints.First(); if (endpoint != null) { SetValue(endpoint.Component, target, endpoint.Property, tp); } } } }
protected override void Inject(object source, object target) { foreach (var targetProp in target.GetType().GetProperties()) { var endpoints = UberFlatter.Flat(targetProp.Name, source); if (endpoints.Count() == 0) { continue; } var desc = endpoints.First(); var result = Convert.ChangeType(desc.Property.GetValue(desc.Component), targetProp.PropertyType); targetProp.SetValue(target, 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); } } } }
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 TypeDescriptor.GetProperties(target)) { PropertyDescriptor t1 = propertyDescriptor; IEnumerable <PropertyWithComponent> source1 = UberFlatter.Flat(propertyDescriptor.Name, source); if (source1.Count() != 0) { PropertyWithComponent propertyWithComponent = source1.First(); if (propertyWithComponent != null) { object sourcePropertyValue = propertyWithComponent.Property.GetValue(propertyWithComponent.Component); object targetValue = GetTargetValue(propertyWithComponent.Property.PropertyType, sourcePropertyValue, propertyDescriptor.PropertyType); propertyDescriptor.SetValue(target, targetValue); } } } }
protected override void Inject(object source, object target) { foreach (PropertyDescriptor targetPropertyDescriptor in target.GetProps()) { var t1 = targetPropertyDescriptor; var es = UberFlatter.Flat(targetPropertyDescriptor.Name, source, type => TypesMatch(type, t1.PropertyType)); var endpoint = es.FirstOrDefault(); if (endpoint == null) { continue; } var sourceValue = endpoint.Property.GetValue(endpoint.Component) is TSource ? (TSource)endpoint.Property.GetValue(endpoint.Component) : default(TSource); if (AllowSetValue(sourceValue)) { targetPropertyDescriptor.SetValue(target, SetValue(sourceValue, targetPropertyDescriptor)); } } }
protected override void Inject(object source, object target) { target.InjectFrom(source); foreach (var property in target.GetFlatProps()) { var pd = property.PropertyDescriptor; var es = UberFlatter.Flat(property.FlatAttribute.Name ?? pd.Name, source, x => TypesMatch(x, pd.PropertyType)).ToList(); var endpoint = es.FirstOrDefault(); if (endpoint == null) { continue; } var value = endpoint.Property.GetValue(endpoint.Component); if (AllowSetValue(value)) { pd.SetValue(target, SetValue(value)); } } }
protected override void Inject(object source, object target) { foreach (PropertyDescriptor t in target.GetProps()) { if (t.PropertyType != typeof(TTargetProperty)) { continue; } var values = UberFlatter.Flat(t.Name, source, type => type == typeof(TSourceProperty)); if (!values.Any()) { continue; } var val = values.First().Property.GetValue(values.First().Component); if (AllowSetValue(val)) { t.SetValue(target, SetValue((TSourceProperty)val)); } } }
protected override void Inject(object source, object target) { if (source == null) { return; } foreach (PropertyDescriptor targetProperty in target.GetProps()) { var t1 = targetProperty; var es = UberFlatter.Flat(targetProperty.Name, source, type => TypesMatch(type, t1.PropertyType)); var sourceType = source.GetType(); if (!es.Any() && !sourceType.IsPrimitive && targetProperty.PropertyType != typeof(String) && !targetProperty.PropertyType.IsInterface) { var sourceProperty = source.GetType().GetProperty(targetProperty.Name); if (sourceProperty != null) { var sourceValue = sourceProperty.GetValue(source, null); if (sourceValue != null) { object targetValue = null; if (sourceProperty.PropertyType.IsSubclassOf(typeof(DbEntity)) && targetProperty.PropertyType.IsSubclassOf(typeof(BusinessEntity))) { var idprop = sourceProperty.PropertyType.GetProperty("Id"); if (idprop != null && idprop.PropertyType == typeof(Int32)) { targetValue = BaseUserContext.TryGetDynamicInstance(targetProperty.PropertyType, Convert.ToInt32(idprop.GetValue(sourceValue, null))); } } if (targetValue == null) { targetValue = Activator.CreateInstance(targetProperty.PropertyType); if (targetValue != null) { Inject(sourceValue, targetValue); } if (targetValue is BusinessEntity) { BaseUserContext.StoreDynamicInstance(targetProperty.PropertyType, targetValue as BusinessEntity); } } targetProperty.SetValue(target, targetValue); } } } Debug.Assert(es != null, "es != null"); var endpoint = es.FirstOrDefault(el => el != null); if (endpoint == null) { continue; } var val = endpoint.Property.GetValue(endpoint.Component); if (AllowSetValue(val)) { targetProperty.SetValue(target, SetValue(val)); } } }