Ejemplo n.º 1
0
        public static bool Run(DependencyObject root, string targetMethodName, object?[] inputParams,
                               [NotNullWhen(true)] out object?result)
        {
            Log.Information("Search Tree Run Method {MethodName}", targetMethodName);
            var pathComponents = ReflectionHelper.SplitPathString(targetMethodName).ToList();
            var methodName     = pathComponents.LastOrDefault() ?? "";
            var targets        = AddPathFollowing(TargetSelector.ResolveTarget(root), pathComponents);

            foreach (var target in targets)
            {
                if (target == null)
                {
                    continue;
                }
                Log.Debug("Searching Object: {target}", target.ToString());
                if (TryInvokeMethod(root, inputParams, target, methodName, out result))
                {
                    return(true);
                }

                if (TryInvokeCommand(inputParams, methodName, target))
                {
                    return(true);
                }
            }

            Log.Error("Failed to bind method: {MethodName}", targetMethodName);
            result = null;
            return(false);
        }
Ejemplo n.º 2
0
        public void ImplicitTargetTest()
        {
            object target = new object();
            var    elt    = new FrameworkElement();

            elt.DataContext = target;
            Assert.Equal(target, TargetSelector.ResolveTarget(elt).First());
        }
Ejemplo n.º 3
0
        public void ExplicitTargetTest()
        {
            object target = new object();
            var    elt    = new FrameworkElement();

            TargetSelector.SetTargetProperty(elt, target);
            Assert.Equal(target, TargetSelector.ResolveTarget(elt).First());
        }
Ejemplo n.º 4
0
        public void EmptyFallThrough()
        {
            var elt             = new FrameworkElement();
            var resolvedTargets = TargetSelector.ResolveTarget(elt).ToList();

            Assert.Single(resolvedTargets); // just the element
            Assert.Equal(elt, resolvedTargets.First());
        }
 public VisualTreeRunContext(
     IDIIntegration diIntegration, DependencyObject root, string targetMethodName,
     IEnumerable <object?> inputParameters)
 {
     DIIntegration    = diIntegration;
     Root             = root;
     TargetMethodName = targetMethodName;
     InputParameters  = inputParameters.ToArray();
     Targets          = TargetSelector.ResolveTarget(
         Root, diIntegration.GetRequired <TargetListCompositeExpander>());
     CandidateParameters =
         DIIntegration.GetRequired <ParameterListCompositeExpander>()
         .Expand(InputParameters.Concat(Targets));
 }
Ejemplo n.º 6
0
 private IList <object> Targets(DependencyObject root) =>
 TargetSelector.ResolveTarget(root, new(Array.Empty <ITargetListExpander>()));