public override Type GetChildDataContextType(Type dataContext, Type parentDataContext, DotvvmControl control)
 {
     var type = control.GetType();
     var property = type.GetProperty(PropertyName);
     if (property == null) throw new Exception($"property { PropertyName } does not exists on { type.FullName }.");
     return property.GetValue(control).GetType();
 }
Example #2
0
        public static CommandBindingExpression GetExtensionCommand(this DotvvmControl control, string methodUsageId)
        {
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.ResolveProperty(typeof(PropertyBox), propertyName);

            return(control.GetCommandBinding(property) as CommandBindingExpression);
        }
Example #3
0
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.Register <object, ExtensionCommands>(propertyName);
            var binding      = new CommandBindingExpression(action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
Example #4
0
        public static CommandBindingExpression?GetExtensionCommand(this DotvvmControl control, string methodUsageId)
        {
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.ResolveProperty(typeof(PropertyBox), propertyName);

            if (property is null)
            {
                throw new Exception($"Extension command {propertyName} has not been registered.");
            }
            return(control.GetCommandBinding(property) as CommandBindingExpression);
        }
Example #5
0
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var bindingService = control.GetValue(Internal.RequestContextProperty).CastTo <IDotvvmRequestContext>()
                                 .Configuration.ServiceProvider.GetRequiredService <BindingCompilationService>();
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.ResolveProperty(typeof(PropertyBox), propertyName) ?? DotvvmProperty.Register(propertyName, typeof(object), typeof(PropertyBox), null, false, null, typeof(PropertyBox), throwOnDuplicitRegistration: false);
            var binding      = new CommandBindingExpression(bindingService, action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
Example #6
0
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var bindingService = control.GetValue(Internal.RequestContextProperty).CastTo <IDotvvmRequestContext>()
                                 .Configuration.ServiceLocator.GetService <BindingCompilationService>();
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.Register <object, PropertyBox>(propertyName);
            var binding      = new CommandBindingExpression(bindingService, action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
        public object ExecuteBinding(string expression, object[] contexts, DotvvmControl control)
        {
            var context = new DataContextStack(contexts.FirstOrDefault()?.GetType() ?? typeof(object));

            context.RootControlType = control?.GetType() ?? typeof(DotvvmControl);
            for (int i = 1; i < contexts.Length; i++)
            {
                context = new DataContextStack(contexts[i].GetType(), context);
            }
            var parser         = new CompileTimeBindingParser();
            var expressionTree = parser.Parse(expression, context, BindingParserOptions.Create <ValueBindingExpression>());

            return(new BindingCompilationAttribute().CompileToDelegate(expressionTree, context, typeof(object)).Compile()(contexts, control));
        }
        public object ExecuteBinding(string expression, object[] contexts, DotvvmControl control, NamespaceImport[] imports = null, Type expectedType = null)
        {
            var context = DataContextStack.Create(contexts.FirstOrDefault()?.GetType() ?? typeof(object), extensionParameters: new[] {
                new CurrentMarkupControlExtensionParameter(new ResolvedTypeDescriptor(control?.GetType() ?? typeof(DotvvmControl)))
            });

            for (int i = 1; i < contexts.Length; i++)
            {
                context = DataContextStack.Create(contexts[i].GetType(), context);
            }
            Array.Reverse(contexts);
            var binding = new ResourceBindingExpression(bindingService, new object[] {
                context,
                new OriginalStringBindingProperty(expression),
                new BindingParserOptions(typeof(ResourceBindingExpression), importNamespaces: imports?.ToImmutableList()),
                new ExpectedTypeBindingProperty(expectedType ?? typeof(object))
            });

            return(binding.BindingDelegate.Invoke(contexts, control));
        }
Example #9
0
        public object ExecuteBinding(string expression, object[] contexts, DotvvmControl control, NamespaceImport[] imports = null, Type expectedType = null)
        {
            var context = new DataContextStack(contexts.FirstOrDefault()?.GetType() ?? typeof(object), rootControlType: control?.GetType() ?? typeof(DotvvmControl));

            for (int i = 1; i < contexts.Length; i++)
            {
                context = new DataContextStack(contexts[i].GetType(), context);
            }
            var parser         = new BindingExpressionBuilder();
            var expressionTree = parser.Parse(expression, context, BindingParserOptions.Create <ValueBindingExpression>(importNs: new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") }.Concat(imports ?? Enumerable.Empty <NamespaceImport>()).ToArray()));

            Array.Reverse(contexts);
            return(new BindingCompilationAttribute().CompileToDelegate(expressionTree, context, expectedType ?? typeof(object)).Compile()(contexts, control));
        }