protected override object GetDependency(IAutowireContext context, Node node)
        {
            Ensure.Any.IsNotNull(context, nameof(context));

            Ensure.Any.IsNotNull(node, nameof(node),
                                 opts => opts.WithMessage(
                                     "[Ancestor] attribute is only supported on members of a Node type class."));

            Ensure.Bool.IsFalse(Enumerable, nameof(node),
                                opts => opts.WithMessage(
                                    "[Ancestor] attribute can't be used on an IEnumerable<T> type field or property."));

            var ancestor = node;

            while ((ancestor = ancestor.GetParent()) != null)
            {
                if (!DependencyType.IsInstanceOfType(ancestor))
                {
                    continue;
                }

                return(ancestor);
            }

            return(null);
        }
Example #2
0
        protected override IEnumerable GetDependencies(IAutowireContext context, Node node)
        {
            Ensure.That(node, nameof(node)).IsNotNull();

            var ancestors = node.GetAncestors().Bind(c =>
            {
                var a = c.FindDelegate().IfNone(c);

                return(DependencyType.IsInstanceOfType(a)
                    ? Some(a)
                    : Some(a).OfType <IGameNodeFactory>().Bind(f => f.Service.ToOption()));
            });

            return(EnumerableHelper.OfType(ancestors.Freeze(), DependencyType));
        }