Ejemplo n.º 1
0
        /// <exception cref="XmlSerializationException">
        ///   The member contains a derived type which is not explicitly defined by an XmlTypeDefAttribute which is required by the
        ///   current serialization settings.
        /// </exception>
        private void WriteMember(
            XmlSerializableMember member, Object memberValue, Boolean asAttribute,
            IEnumerable <XmlItemDefAttribute> itemAttributeOverrides = null
            )
        {
            XmlItemDefAttributeCollection itemDefAttributes = new XmlItemDefAttributeCollection(member.MemberInfo.ItemDefAttributes);

            if (itemAttributeOverrides != null)
            {
                itemDefAttributes.AddRange(itemAttributeOverrides);
            }

            String nameToWrite;

            if (memberValue != null)
            {
                Type    objectType = memberValue.GetType();
                Boolean typeIsExplicitlyDefined;
                nameToWrite = member.MemberInfo.GetMemberNameByType(objectType, out typeIsExplicitlyDefined);
                if (!typeIsExplicitlyDefined && this.Settings.RequiresExplicitTypeDefinition)
                {
                    var ex = new XmlSerializationException("The member contains a derived type which is not explicitly defined by an XmlTypeDefAttribute which is required by the current serialization settings.");
                    ex.Data.Add("MemberInfo", member.MemberInfo);
                    ex.Data.Add("Derived Type", objectType);
                    throw ex;
                }
            }
            else
            {
                nameToWrite = member.MemberInfo.Name;
            }

            this.WriteNode(nameToWrite, memberValue, asAttribute, itemDefAttributes, member.MemberInfo.Comment);
        }
Ejemplo n.º 2
0
        private Object ReadMemberContent(XmlMemberInfo memberInfo, IEnumerable <XmlItemDefAttribute> itemDefAttributeOverrides = null)
        {
            XmlItemDefAttributeCollection itemDefAttributes = new XmlItemDefAttributeCollection(memberInfo.ItemDefAttributes);

            if (itemDefAttributeOverrides != null)
            {
                itemDefAttributes.AddRange(itemDefAttributeOverrides);
            }

            return(this.ReadElementContent(memberInfo.Type, itemDefAttributes));
        }