/// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="constraint"></param>
        /// <returns></returns>
        public IEnumerable <object> ResolveAll(Type type, IConstraint constraint)
        {
            if (constraint == null)
            {
                return(table.GetOrAdd(type, bindingsFactory)
                       .Select(b => Resolve(b)));
            }

            return(table.GetOrAdd(type, bindingsFactory)
                   .Where(b => constraint.Match(b.Metadata))
                   .Select(b => Resolve(b)));
        }
예제 #2
0
        public static void That(object expression, IConstraint constraint, object message, params object[] args)
        {
            var msg = (message != null)
                ? string.Format(message.ToString(), args)
                : string.Empty;

            if (!constraint.Match(expression))
            {
                IMessageWriter writer = new TextMessageWriter(msg ?? "");
                writer.BuildMessage(constraint);
                throw new AssertionException(writer.ToString());
            }
        }
        // ------------------------------------------------------------
        // Binding
        // ------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="constraint"></param>
        /// <returns></returns>
        private IBinding FindBinding(Type type, IConstraint constraint)
        {
            var list = table.GetOrAdd(type, bindingsFactory);

            if (list.Length == 0)
            {
                return(null);
            }

            if (constraint == null)
            {
                return(list[list.Length - 1]);
            }

            for (var i = list.Length - 1; i >= 0; i--)
            {
                if (constraint.Match(list[i].Metadata))
                {
                    return(list[i]);
                }
            }

            return(null);
        }