public override JsExpression GetJsTranslation(JsExpression dataContext) { return(dataContext.Member("$control").WithAnnotation(new ViewModelInfoAnnotation(ResolvedTypeDescriptor.ToSystemType(this.ParameterType), isControl: true))); }
public override Expression GetServerEquivalent(Expression controlParameter) { return(Expression.Convert(ExpressionUtils.Replace((DotvvmBindableObject c) => c.GetClosestControlBindingTarget(), controlParameter), ResolvedTypeDescriptor.ToSystemType(ParameterType))); }
/// This is a strange conversion that wraps the entire expression into a Lambda /// and makes an invokable delegate from a normal expression. /// It also replaces special ExtensionParameters attached to the expression for lambda parameters public static Expression MagicLambdaConversion(Expression expr, Type expectedType) { if (expectedType.IsDelegate()) { var resultType = expectedType.GetMethod("Invoke").ReturnType; var delegateArgs = expectedType .GetMethod("Invoke") .GetParameters() .Select(p => Expression.Parameter(p.ParameterType, p.Name)) .ToArray(); var convertedToResult = TypeConversion.ImplicitConversion(expr, resultType) ?? TaskConversion(expr, resultType); // TODO: convert delegates to another delegates if (convertedToResult == null) { return(null); } else { var replacedArgs = convertedToResult.ReplaceAll(arg => arg?.GetParameterAnnotation()?.ExtensionParameter is MagicLambdaConversionExtensionParameter extensionParam ? delegateArgs.Single(a => a.Name == extensionParam.Identifier) .Assert(p => p.Type == ResolvedTypeDescriptor.ToSystemType(extensionParam.ParameterType)) : arg ); return(Expression.Lambda( expectedType, replacedArgs, delegateArgs )); } } else { return(null); } }
protected override IControlType CreateControlType(ITypeDescriptor wrapperType, string virtualPath) { return(new ControlType(ResolvedTypeDescriptor.ToSystemType(wrapperType), virtualPath: virtualPath)); }
static ParameterExpression CreateParameter(DataContextStack stackItem, string name, BindingExtensionParameter extensionParameter = null) => Expression.Parameter((extensionParameter == null ? stackItem.DataContextType : ResolvedTypeDescriptor.ToSystemType(extensionParameter.ParameterType)) ?? typeof(ExpressionHelper.UnknownTypeSentinel), name) .AddParameterAnnotation(new BindingParameterAnnotation(stackItem, extensionParameter));