コード例 #1
0
 protected override bool DoMustDeclareTypeNameInXmlElement(Type entityType, XmlSerializerContext context)
 {
     //las listas no necesitan declarar el tipo, se crea un tipo por defecto....
     //si es generica y es root, se debe declarar el tipo.
     if (entityType.IsGenericType && context.IsRootElement(this))
     {
         return(true);
     }
     else
     {
         return(false); //entityType != this.PropertyType;
     }
 }
コード例 #2
0
        /// <summary>
        /// Devuelve un booleano que indica si debe escribir el tipo
        /// </summary>
        /// <param name="propertyEntityType"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public virtual bool MustDeclareTypeNameInXmlElement(Type entityType, XmlSerializerContext context)
        {
            bool isRoot = context.IsRootElement(this);

            if (isRoot)
            {
                return(context.MustDeclareRootTypeName(entityType));
            }
            else
            {
                return(this.DoMustDeclareTypeNameInXmlElement(entityType, context));
            }
        }
コード例 #3
0
        protected override bool DoMustDeclareTypeNameInXmlElement(Type entityType, XmlSerializerContext context)
        {
            bool output = base.DoMustDeclareTypeNameInXmlElement(entityType, context);

            if (output)
            {
                if (entityType.IsArray)
                {
                    return(true);
                }

                if (context.IsRootElement(this))
                {
                    if (entityType.IsGenericType)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (this.Metadata.PropertyType.IsInterface)
                {
                    if (this.Metadata.PropertyType.IsGenericType)
                    {
                        return(!this.Metadata.PropertyType.Name.StartsWith("IList"));
                    }
                    else
                    {
                        return(!this.Metadata.PropertyType.Equals(typeof(IList)));
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }