Exemplo n.º 1
0
        // public static methods
        /// <summary>
        /// Looks up the effective set of conventions that apply to a type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The conventions for that type.</returns>
        public static IConventionPack Lookup(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            lock (__lock)
            {
                var pack = new ConventionPack();

                // append any attribute packs (usually just one) at the end so attributes are processed last
                var attributePacks = new List <IConventionPack>();
#pragma warning disable 618 //obsoleted by ConventionProfile
                ConventionProfile conventionProfile = null;
#pragma warning restore 618
                foreach (var container in __conventionPacks)
                {
                    if (container.Filter(type))
                    {
#pragma warning disable 618 //obsoleted by ConventionProfile
                        if (container.Pack is ConventionProfile)
                        {
                            conventionProfile = container.Pack as ConventionProfile;
                        }
#pragma warning restore 618

                        if (container.Name == "__attributes__")
                        {
                            attributePacks.Add(container.Pack);
                        }
                        else
                        {
                            pack.Append(container.Pack);
                        }
                    }
                }
                if (conventionProfile != null)
                {
                    // already includes the default attribute convention pack
                    return(conventionProfile);
                }

                foreach (var attributePack in attributePacks)
                {
                    pack.Append(attributePack);
                }

                return(pack);
            }
        }