/// <summary>
        /// We look for attributes implementing IFixtureBuilder at one level 
        /// of inheritance at a time. Attributes on base classes are not used 
        /// unless there are no fixture builder attributes at all on the derived
        /// class. This is by design.
        /// </summary>
        /// <param name="type">The type being examined for attributes</param>
        /// <returns>A list of the attributes found.</returns>
        private IFixtureBuilder[] GetFixtureBuilderAttributes(Type type)
        {
            IFixtureBuilder[] attrs = new IFixtureBuilder[0];

            while (type != null)
            {
                attrs = (IFixtureBuilder[])type.GetCustomAttributes(typeof(IFixtureBuilder), false);

                if (attrs.Length > 0)
                    return attrs;

                type = type.BaseType;
            }

            return attrs;
        }
        private bool HasArguments(IFixtureBuilder attr)
        {
            // Only TestFixtureAttribute can be used without arguments
            var temp = attr as TestFixtureAttribute;

            return temp == null || temp.Arguments.Length > 0 || temp.TypeArgs.Length > 0;
        }
        private Test BuildMultipleFixtures(Type type, IFixtureBuilder[] attrs)
        {
            TestSuite suite = new ParameterizedFixtureSuite(type);

            foreach (IFixtureBuilder attr in attrs)
                suite.Add(attr.BuildFrom(type));

            return suite;
        }
        /// <summary>
        /// We look for attributes implementing IFixtureBuilder at one level 
        /// of inheritance at a time. Attributes on base classes are not used 
        /// unless there are no fixture builder attributes at all on the derived
        /// class. This is by design.
        /// </summary>
        /// <param name="typeInfo">The type being examined for attributes</param>
        /// <returns>A list of the attributes found.</returns>
        private IFixtureBuilder[] GetFixtureBuilderAttributes(ITypeInfo typeInfo)
        {
            IFixtureBuilder[] attrs = new IFixtureBuilder[0];

            while (typeInfo != null && !typeInfo.IsType(typeof(object)))
            {
                attrs = typeInfo.GetCustomAttributes<IFixtureBuilder>(false);

                if (attrs.Length > 0)
                {
                    // We want to eliminate duplicates that have no args.
                    // If there is just one, no duplication is possible.
                    if (attrs.Length == 1)
                        return attrs;

                    // Count how many have arguments
                    int withArgs = 0;
                    foreach (var attr in attrs)
                        if (HasArguments(attr))
                            withArgs++;

                    // If all have args, just return them
                    if (withArgs == attrs.Length)
                        return attrs;

                    // If none of them have args, return the first one
                    if (withArgs == 0)
                        return new IFixtureBuilder[] { attrs[0] };
                    
                    // Some of each - extract those with args
                    var result = new IFixtureBuilder[withArgs];
                    int count = 0;
                    foreach (var attr in attrs)
                        if (HasArguments(attr))
                            result[count++] = attr;

                    return result;
                }

                typeInfo = typeInfo.BaseType;
            }

            return attrs;
        }