Exemplo n.º 1
0
 public override JsExpression GetJsTranslation(JsExpression dataContext)
 {
     return(dataContext.Member("$control").WithAnnotation(new ViewModelInfoAnnotation(ResolvedTypeDescriptor.ToSystemType(this.ParameterType), isControl: true)));
 }
Exemplo n.º 2
0
 public override Expression GetServerEquivalent(Expression controlParameter)
 {
     return(Expression.Convert(ExpressionUtils.Replace((DotvvmBindableObject c) => c.GetClosestControlBindingTarget(), controlParameter), ResolvedTypeDescriptor.ToSystemType(ParameterType)));
 }
Exemplo n.º 3
0
        /// 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);
            }
        }
Exemplo n.º 4
0
 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));