/// <summary> /// Initializes a new instance of the <see cref="DataBindingSetterBuilder"/> class. /// </summary> /// <param name="expressionType">The type of the bound expression.</param> /// <param name="dataSourceType">The type of the data source to which the value is being bound.</param> /// <param name="expression">The binding expression with which to bind the dependency property.</param> public DataBindingSetterBuilder(Type expressionType, Type dataSourceType, String expression) : base(dataSourceType) { this.boundType = expressionType; this.delegateType = typeof(DataBindingSetter <>).MakeGenericType(expressionType); CreateReturnTarget(); var path = BindingExpressions.GetBindingMemberPathPart(expression); var current = AddDataSourceReference(); var value = AddValueParameter(); if (current.Type.IsValueType) { return; } if (!AddValueAssignment(current, value, path)) { return; } AddReturn(); AddReturnLabel(); var lambdaBody = Expression.Block(variables, expressions); var lambda = Expression.Lambda(delegateType, lambdaBody, parameters); lambdaExpression = lambda; }
/// <summary> /// Initializes a new instance of the <see cref="DataBindingSetterBuilder"/> class. /// </summary> /// <param name="expressionType">The type of the bound expression.</param> /// <param name="dataSourceType">The type of the data source to which the value is being bound.</param> /// <param name="expression">The binding expression with which to bind the dependency property.</param> public DataBindingSetterBuilder(Type expressionType, Type dataSourceType, String expression) : base(dataSourceType) { this.boundType = expressionType; this.delegateType = typeof(DataBindingSetter <>).MakeGenericType(expressionType); #if CODE_GEN_ENABLED CreateReturnTarget(); var path = BindingExpressions.GetBindingMemberPathPart(expression); var current = AddDataSourceReference(); var value = AddValueParameter(); if (current.Type.IsValueType) { return; } if (!AddValueAssignment(current, value, path)) { return; } AddReturn(); AddReturnLabel(); var lambdaBody = Expression.Block(variables, expressions); var lambda = Expression.Lambda(delegateType, lambdaBody, parameters); lambdaExpression = lambda; #else var expParamDataSource = Expression.Parameter(typeof(Object), "dataSource"); var expParamValue = Expression.Parameter(boundType, "value"); var implMethod = typeof(DataBindingSetterBuilder).GetMethod(nameof(ReflectionBasedImplementation), BindingFlags.NonPublic | BindingFlags.Static); var path = BindingExpressions.GetBindingMemberPathPart(expression); var property = dataSourceType.GetProperty(path); if (!property.CanWrite) { return; } var expImplMethodCall = Expression.Call(implMethod, Expression.Constant(property), Expression.Convert(expParamDataSource, typeof(Object)), Expression.Convert(expParamValue, typeof(Object))); lambdaExpression = Expression.Lambda(delegateType, expImplMethodCall, expParamDataSource, expParamValue); #endif }
/// <summary> /// Initializes a new instance of the <see cref="DataBindingGetterBuilder"/> class. /// </summary> /// <param name="expressionType">The type of the bound expression.</param> /// <param name="dataSourceType">The type of the data source to which the expression is being bound.</param> /// <param name="expression">The binding expression with which to bind the dependency property.</param> public DataBindingGetterBuilder(Type expressionType, Type dataSourceType, String expression) : base(dataSourceType) { this.delegateType = typeof(DataBindingGetter <>).MakeGenericType(expressionType); #if CODE_GEN_ENABLED CreateReturnTarget(expressionType); var path = BindingExpressions.GetBindingMemberPathPart(expression); var current = AddDataSourceReference(); current = AddSafeReference(expression, current, path); var result = Expression.Convert(current, expressionType); AddReturn(result); AddReturnLabel(); var lambdaBody = Expression.Block(variables, expressions); var lambda = Expression.Lambda(delegateType, lambdaBody, parameters); lambdaExpression = lambda; #else var expParamDataSource = Expression.Parameter(typeof(Object), "dataSource"); var implMethod = typeof(DataBindingGetterBuilder).GetMethod(nameof(ReflectionBasedImplementation), BindingFlags.NonPublic | BindingFlags.Static); var path = BindingExpressions.GetBindingMemberPathPart(expression); var property = dataSourceType.GetProperty(path); if (!property.CanRead) { return; } var expImplMethodCall = Expression.Call(implMethod, Expression.Constant(property), Expression.Convert(expParamDataSource, typeof(Object))); lambdaExpression = Expression.Lambda(delegateType, Expression.Convert( Expression.Convert(expImplMethodCall, property.PropertyType), expressionType), expParamDataSource); #endif }
/// <summary> /// Initializes a new instance of the <see cref="BoundEventBuilder"/> type. /// </summary> /// <param name="dataSource">The data source to which the event is being bound.</param> /// <param name="dataSourceType">The type of the data source to which the expression is being bound.</param> /// <param name="delegateType">The type of delegate that will be created to bind to the event.</param> /// <param name="expression">The binding expression that represents the method to bind to the event.</param> public BoundEventBuilder(Object dataSource, Type dataSourceType, Type delegateType, String expression) : base(dataSourceType) { CreateParameters(delegateType); CreateReturnTarget(); var path = BindingExpressions.GetBindingMemberPathPart(expression, false); var current = AddDataSourceReference(expression, dataSource, dataSourceType); current = AddMethodInvocation(expression, current, path); AddReturn(); AddReturnLabel(); var lambdaBody = Expression.Block(variables, expressions); var lambda = Expression.Lambda(delegateType, lambdaBody, parameters); lambdaExpression = lambda; }
/// <summary> /// Initializes a new instance of the <see cref="DataBindingGetterBuilder"/> class. /// </summary> /// <param name="expressionType">The type of the bound expression.</param> /// <param name="dataSourceType">The type of the data source to which the expression is being bound.</param> /// <param name="expression">The binding expression with which to bind the dependency property.</param> public DataBindingGetterBuilder(Type expressionType, Type dataSourceType, String expression) : base(dataSourceType) { this.delegateType = typeof(DataBindingGetter <>).MakeGenericType(expressionType); CreateReturnTarget(expressionType); var path = BindingExpressions.GetBindingMemberPathPart(expression); var current = AddDataSourceReference(); current = AddSafeReference(expression, current, path); var result = Expression.Convert(current, expressionType); AddReturn(result); AddReturnLabel(); var lambdaBody = Expression.Block(variables, expressions); var lambda = Expression.Lambda(delegateType, lambdaBody, parameters); lambdaExpression = lambda; }