Пример #1
0
        // public methods
        /// <summary>
        /// Merges another convention profile into this one (only missing conventions are merged).
        /// </summary>
        /// <param name="other">The other convention profile.</param>
        public void Merge(ConventionProfile other)
        {
            if (DefaultValueConvention == null)
            {
                DefaultValueConvention = other.DefaultValueConvention;
            }
            if (ElementNameConvention == null)
            {
                ElementNameConvention = other.ElementNameConvention;
            }
            if (ExtraElementsMemberConvention == null)
            {
                ExtraElementsMemberConvention = other.ExtraElementsMemberConvention;
            }
            if (IdGeneratorConvention == null)
            {
                IdGeneratorConvention = other.IdGeneratorConvention;
            }
            if (IdMemberConvention == null)
            {
                IdMemberConvention = other.IdMemberConvention;
            }
            if (IgnoreExtraElementsConvention == null)
            {
                IgnoreExtraElementsConvention = other.IgnoreExtraElementsConvention;
            }
#pragma warning disable 618 // SerializeDefaultValueConvention is obsolete
            if (IgnoreIfDefaultConvention == null && SerializeDefaultValueConvention == null)
            {
                if (other.SerializeDefaultValueConvention != null)
                {
                    SerializeDefaultValueConvention = other.SerializeDefaultValueConvention;
                }
                else
                {
                    IgnoreIfDefaultConvention = other.IgnoreIfDefaultConvention;
                }
            }
#pragma warning restore 618
            if (IgnoreIfNullConvention == null)
            {
                IgnoreIfNullConvention = other.IgnoreIfNullConvention;
            }
            if (MemberFinderConvention == null)
            {
                MemberFinderConvention = other.MemberFinderConvention;
            }
            if (SerializationOptionsConvention == null)
            {
                SerializationOptionsConvention = other.SerializationOptionsConvention;
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
 // public methods
 /// <summary>
 /// Merges another convention profile into this one (only missing conventions are merged).
 /// </summary>
 /// <param name="other">The other convention profile.</param>
 public void Merge(ConventionProfile other)
 {
     if (DefaultValueConvention == null)
     {
         DefaultValueConvention = other.DefaultValueConvention;
     }
     if (ElementNameConvention == null)
     {
         ElementNameConvention = other.ElementNameConvention;
     }
     if (ExtraElementsMemberConvention == null)
     {
         ExtraElementsMemberConvention = other.ExtraElementsMemberConvention;
     }
     if (IdGeneratorConvention == null)
     {
         IdGeneratorConvention = other.IdGeneratorConvention;
     }
     if (IdMemberConvention == null)
     {
         IdMemberConvention = other.IdMemberConvention;
     }
     if (IgnoreExtraElementsConvention == null)
     {
         IgnoreExtraElementsConvention = other.IgnoreExtraElementsConvention;
     }
     #pragma warning disable 618 // SerializeDefaultValueConvention is obsolete
     if (IgnoreIfDefaultConvention == null && SerializeDefaultValueConvention == null)
     {
         if (other.SerializeDefaultValueConvention != null)
         {
             SerializeDefaultValueConvention = other.SerializeDefaultValueConvention;
         }
         else
         {
             IgnoreIfDefaultConvention = other.IgnoreIfDefaultConvention;
         }
     }
     #pragma warning restore 618
     if (IgnoreIfNullConvention == null)
     {
         IgnoreIfNullConvention = other.IgnoreIfNullConvention;
     }
     if (MemberFinderConvention == null)
     {
         MemberFinderConvention = other.MemberFinderConvention;
     }
     if (SerializationOptionsConvention == null)
     {
         SerializationOptionsConvention = other.SerializationOptionsConvention;
     }
 }