/// <summary> /// Maps the object properties for the given object. /// </summary> /// <param name="expressions">The parent expression list.</param> /// <param name="objectType">Type of the object.</param> /// <param name="context">The window builder context.</param> private void MapObjectProperties(ICollection <Expression> expressions, Type objectType, ControlBuilderContext context) { // ReSharper disable LoopCanBeConvertedToQuery foreach (var propertyInfo in objectType.GetProperties().Where(p => p.SetMethod != null && p.CanWrite && p.PropertyType.IsSupportedPropertyType(typeof(TControl)))) { var propertyType = propertyInfo.PropertyType; var attribute = propertyInfo.GetCustomAttributes(typeof(ControlLocatorAttribute), false).FirstOrDefault() as ControlLocatorAttribute; var customAttributes = this.GetCustomAttributes(propertyInfo); if (attribute == null && customAttributes.Length == 0) { continue; } // Final Properties var itemVariable = Expression.Variable(propertyType); context.CurrentControl = new ExpressionData(itemVariable, propertyType, propertyInfo.Name); var variableList = new List <ParameterExpression> { itemVariable }; var propertyExpressions = new List <Expression>(); // New up property and then check it for inner properties. var childContext = context.CreateChildContext(context.CurrentControl); propertyExpressions.AddRange(this.CreateWinControlObject(childContext, attribute, customAttributes)); this.MapObjectProperties(propertyExpressions, propertyType, childContext); propertyExpressions.Add(Expression.Assign(Expression.Property(context.Window.Expression, propertyInfo), itemVariable)); expressions.Add(Expression.Block(variableList, propertyExpressions)); } }