示例#1
0
        private void DeserializeAttributes(object parent, TypeDescriptor entityTypeDescriptor, XmlReader reader, XmlSerializerContext context)
        {
            //avanzo hasta el primer atributo
            bool isAtt = reader.MoveToFirstAttribute();
            PropertyDescriptor prop;
            //si es un atributo, el tipo de la entidad coincide con el definido en la propiedad...

            string attName;
            object value;

            if (isAtt)
            {
                do
                {
                    attName = reader.Name;
                    prop    = entityTypeDescriptor.GetPropertyByAttributeName(attName);

                    if (prop != null)
                    {
                        //obtengo el tipo a partir del atributo
                        Type propType = prop.GetTypeFromAttributeName(attName, context);

                        IXmlConverter converter = context.GetConverter(propType);
                        value = converter.FromXml(parent, prop, propType, reader, context);
                        prop.Metadata.SetValue(parent, value);
                    }
                    else
                    {
                        //if (! (string.Compare(context.Settings.TypeSettings.AttributeTypeName, attName) == 0
                        //    || string.Compare(XmlSerializerSettings.ObjectReferenceAttributeName, attName) == 0
                        //    || string.Compare(XmlSerializerSettings.ObjectIdAttributeName, attName) == 0))
                        //DefaultLogger.Warning("The xml attribute {0} doesn't match with an property of the class {1}", attName, parent.GetType().ToString());
                    }
                }while (reader.MoveToNextAttribute());
            }

            //me ubico de nuevo en el elemento
            reader.MoveToContent();
        }
示例#2
0
        protected override object DoGetValueFromString(ValueTypePropertyDescriptor metadata, string attValue, Type type, XmlSerializerContext context)
        {
            Type t = Type.GetType(attValue);

            if (t == null)
            {
                t = TypeConverter.GetSystemType(attValue);
            }
            return(t);
        }
示例#3
0
 protected override object GetDefaultValue(ValueTypePropertyDescriptor metadata, Type type, XmlSerializerContext context)
 {
     return(null);
 }
 public override bool IsXmlElement(Type entityType, XmlSerializerContext context)
 {
     throw new NotImplementedException();
 }
示例#5
0
 public override string GetValueAsString(ValueTypePropertyDescriptor metadata, object attValue, Type type, XmlSerializerContext context)
 {
     return(this.TypeToString((Type)attValue, context.Settings.TypeSettings));
 }
 protected override bool DoMustDeclareTypeNameInXmlElement(Type entityType, XmlSerializerContext context)
 {
     throw new NotImplementedException();
 }
 public override TPropertyDescriptor GetPropertyDescriptor <TPropertyDescriptor>(Type entityType, XmlSerializerContext context)
 {
     if (typeof(TPropertyDescriptor) == this.GetType())
     {
         return(this as TPropertyDescriptor);
     }
     else
     {
         TPropertyDescriptor output = Activator.CreateInstance(typeof(TPropertyDescriptor), this.Metadata) as TPropertyDescriptor;
         output.UseAlias = true;
         return(output);
     }
 }
示例#8
0
 protected override void DoToNullValueXml(object parent, PropertyDescriptor metadata, XmlTextWriter writer, XmlSerializerContext context)
 {
 }
示例#9
0
        protected override void DoToXml(object parent, PropertyDescriptor metadata, object entity, XmlTextWriter writer, XmlSerializerContext context)
        {
            IXmlSerializable ser = (IXmlSerializable)entity;

            string nodeName = metadata.GetElementNameForType(entity.GetType(), context, true);

            writer.WriteStartElement(nodeName);

            if (!context.Settings.UniqueSerializationForInstance || !context.Stack.ContainsInstance(entity))
            {
                //agrego la lista a las entidades registradas
                long id = context.Stack.AddInstance(entity);

                ser.WriteXml(writer);

                //escribo el id del objeto si corresponde
                if (context.Settings.UniqueSerializationForInstance)
                {
                    writer.WriteAttributeString(XmlSerializerSettings.ObjectIdAttributeName, id.ToString());
                }
            }
            else
            {
                //me fijo si ya existe en el context
                long id = context.Stack.GetInstanceReferenceId(entity);
                writer.WriteAttributeString(XmlSerializerSettings.ObjectReferenceAttributeName, id.ToString());
            }

            writer.WriteEndElement();
        }
示例#10
0
        protected override object DoFromXml(object parent, PropertyDescriptor metadata, Type entityType, XmlReader reader, XmlSerializerContext context)
        {
            long             id     = this.GetInstanceId(reader);
            object           entity = Activator.CreateInstance(entityType, true);
            IXmlSerializable ser    = (IXmlSerializable)entity;

            ser.ReadXml(reader);

            //agrego la instancia al stack
            context.Stack.AddInstance(id, entity);

            return(entity);
        }