Exemplo n.º 1
0
 string ExportDefaultValue(TypeData typeData, XmlTypeMapping map, object defaultValue)
 {
     if (typeData.SchemaType == SchemaTypes.Enum)
     {
         EnumMap enumMap = (EnumMap)map.ObjectMap;
         // get corresponding xml name
         return(enumMap.GetXmlName(map.TypeFullName, defaultValue));
     }
     return(XmlCustomFormatter.ToXmlString(typeData, defaultValue));
 }
Exemplo n.º 2
0
        protected void WriteTypedPrimitive(string name, string ns, object o, bool xsiType)
        {
            string   value;
            TypeData td = TypeTranslator.GetTypeData(o.GetType());

            if (td.SchemaType != SchemaTypes.Primitive)
            {
                throw new InvalidOperationException(String.Format("The type of the argument object '{0}' is not primitive.", td.FullTypeName));
            }

            if (name == null)
            {
                ns   = td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace;
                name = td.XmlType;
            }
            else
            {
                name = XmlCustomFormatter.FromXmlName(name);
            }
            Writer.WriteStartElement(name, ns);

            if (o is XmlQualifiedName)
            {
                value = FromXmlQualifiedName((XmlQualifiedName)o);
            }
            else
            {
                value = XmlCustomFormatter.ToXmlString(td, o);
            }

            if (xsiType)
            {
                if (td.SchemaType != SchemaTypes.Primitive)
                {
                    throw new InvalidOperationException(string.Format(unexpectedTypeError, o.GetType().FullName));
                }
                WriteXsiType(td.XmlType, td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace);
            }

            WriteValue(value);

            Writer.WriteEndElement();
        }
Exemplo n.º 3
0
        protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
        {
            if (o == null)
            {
                if (isNullable)
                {
                    WriteNullTagEncoded(n, ns);
                }
                return;
            }

            WriteStartElement(n, ns, true);

            CheckReferenceQueue();

            if (callbacks != null && callbacks.ContainsKey(o.GetType()))
            {
                WriteCallbackInfo info = (WriteCallbackInfo)callbacks[o.GetType()];
                if (o.GetType().IsEnum)
                {
                    info.Callback(o);
                }
                else if (suppressReference)
                {
                    Writer.WriteAttributeString("id", GetId(o, false));
                    if (ambientType != o.GetType())
                    {
                        WriteXsiType(info.TypeName, info.TypeNs);
                    }
                    info.Callback(o);
                }
                else
                {
                    if (!AlreadyQueued(o))
                    {
                        referencedElements.Enqueue(o);
                    }
                    Writer.WriteAttributeString("href", "#" + GetId(o, true));
                }
            }
            else
            {
                // Must be a primitive type or array of primitives
                TypeData td = TypeTranslator.GetTypeData(o.GetType());
                if (td.SchemaType == SchemaTypes.Primitive)
                {
                    WriteXsiType(td.XmlType, XmlSchema.Namespace);
                    Writer.WriteString(XmlCustomFormatter.ToXmlString(td, o));
                }
                else if (IsPrimitiveArray(td))
                {
                    if (!AlreadyQueued(o))
                    {
                        referencedElements.Enqueue(o);
                    }
                    Writer.WriteAttributeString("href", "#" + GetId(o, true));
                }
                else
                {
                    throw new InvalidOperationException("Invalid type: " + o.GetType().FullName);
                }
            }

            WriteEndElement();
        }