public ResolutionResult resolve(ResolutionContext context) { ResolutionResult result = new ResolutionResult(context); List<MemberBinding> memberBindings = new List<MemberBinding>(); var targetProperties = from property in context.TargetType.GetProperties(BindingFlags.Public | BindingFlags.Instance) where property.CanWrite select property; foreach (PropertyInfo targetProperty in targetProperties) { MappingAttribute attribute = targetProperty.GetAttribute(); if ((attribute == null) || !attribute.Ignored) { string columnName = attribute == null ? targetProperty.Name : attribute.Name; // Create expression representing r.CellValue<property.PropertyType>(property.Name) MethodCallExpression propertyValueExpr = Expression.Call( typeof(DataRowExtensions).GetMethod("CellValue").MakeGenericMethod(targetProperty.PropertyType), context.Parameter, Expression.Constant(columnName)); MemberBinding memberBinding = Expression.Bind(targetProperty, propertyValueExpr); memberBindings.Add(memberBinding); } } result.MemberBindings = memberBindings; return result; }
public ResolutionResult Map(ResolutionContext context) { ResolutionResult result = new ResolutionResult(context); foreach (var resolver in this.AllResolvers) { result.MemberBindings.AddRange(resolver.resolve(context).MemberBindings); } return result; }
public ResolutionResult resolve(ResolutionContext context) { ResolutionResult result = new ResolutionResult(context); List<MemberBinding> memberBindings = new List<MemberBinding>(); var targetProperties = from property in context.TargetType.GetProperties(BindingFlags.Public | BindingFlags.Instance) where property.CanWrite select property; foreach (PropertyInfo targetProperty in targetProperties) { MappingAttribute attribute = targetProperty.GetAttribute(); if ((attribute == null) || !attribute.Ignored) { PropertyInfo sourceProperty = context.SourceType.GetProperty(targetProperty.Name); if (sourceProperty == null) { if (attribute != null) { sourceProperty = context.SourceType.GetProperty(attribute.Name); } if (sourceProperty == null) { continue; } } if (sourceProperty.CanRead) { MemberBinding memberBinding; if (!targetProperty.PropertyType.IsAssignableFrom(sourceProperty.PropertyType)) { memberBinding = Expression.Bind(targetProperty, Expression.Convert(Expression.Property(context.Parameter, sourceProperty), targetProperty.PropertyType)); } else { memberBinding = Expression.Bind(targetProperty, Expression.Property(context.Parameter, sourceProperty)); } memberBindings.Add(memberBinding); } } } result.MemberBindings = memberBindings; return result; }
public ResolutionResult resolve(ResolutionContext context) { ResolutionResult fieldResult = new ResolutionResult(context); List<MemberBinding> bindings = new List<MemberBinding>(); foreach (FieldInfo targetField in from field in context.TargetType.GetFields(BindingFlags.Public | BindingFlags.Instance) select field) { MappingAttribute attribute = targetField.GetAttribute(); if ((attribute == null) || !attribute.Ignored) { MemberBinding memberBinding; FieldInfo sourceField = context.SourceType.GetField(targetField.Name); if (sourceField == null) { if (attribute != null) { sourceField = context.SourceType.GetField(attribute.Name); } if (sourceField == null) { continue; } } if (!targetField.FieldType.IsAssignableFrom(sourceField.FieldType)) { memberBinding = Expression.Bind(targetField, Expression.Convert(Expression.Field(context.Parameter, sourceField), targetField.FieldType)); } else { memberBinding = Expression.Bind(targetField, Expression.Field(context.Parameter, sourceField)); } bindings.Add(memberBinding); } } fieldResult.MemberBindings = bindings; return fieldResult; }
public ResolutionResult(ResolutionContext context) { this.context = context; this.memberBindings = new List<MemberBinding>(); }
public ResolutionResult Map(ResolutionContext context) { ResolutionResult result = new ResolutionResult(context); result.MemberBindings.AddRange(this.AllResolvers[0].resolve(context).MemberBindings); return result; }