Exemple #1
0
 protected static string ToXmlNmTokens(string value)
 {
     return(XmlCustomFormatter.ToXmlNmTokens(value));
 }
Exemple #2
0
 protected static DateTime ToTime(string value)
 {
     return(XmlCustomFormatter.ToTime(value));
 }
Exemple #3
0
 protected static string ToXmlNCName(string value)
 {
     return(XmlCustomFormatter.ToXmlNCName(value));
 }
Exemple #4
0
 protected static char ToChar(string value)
 {
     return(XmlCustomFormatter.ToChar(value));
 }
Exemple #5
0
 protected static long ToEnum(string value, Hashtable h, string typeName)
 {
     return(XmlCustomFormatter.ToEnum(value, h, typeName, true));
 }
Exemple #6
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();
        }
Exemple #7
0
        void WriteStartElement(string name, string ns, object o, bool writePrefixed, ICollection namespaces)
        {
            if (o != null)
            {
                if (serializedObjects.Contains(o))
                {
                    throw new InvalidOperationException("A circular reference was detected while serializing an object of type " + o.GetType().Name);
                }
                else
                {
                    serializedObjects [o] = o;
                }
            }

            string prefix = null;

            if (topLevelElement && ns != null && ns.Length != 0)
            {
                foreach (XmlQualifiedName qn in namespaces)
                {
                    if (qn.Namespace == ns)
                    {
                        prefix        = qn.Name;
                        writePrefixed = true;
                        break;
                    }
                }
            }

            if (writePrefixed && ns != string.Empty)
            {
                name = XmlCustomFormatter.FromXmlName(name);

                if (prefix == null)
                {
                    prefix = Writer.LookupPrefix(ns);
                }
                if (prefix == null || prefix.Length == 0)
                {
                    prefix = "q" + (++qnameCount);
                }
                Writer.WriteStartElement(prefix, name, ns);
            }
            else
            {
                Writer.WriteStartElement(name, ns);
            }

            if (topLevelElement)
            {
                if (namespaces != null)
                {
                    foreach (XmlQualifiedName qn in namespaces)
                    {
                        string currentPrefix = Writer.LookupPrefix(qn.Namespace);
                        if (currentPrefix != null && currentPrefix.Length != 0)
                        {
                            continue;
                        }

                        WriteAttribute("xmlns", qn.Name, xmlNamespace, qn.Namespace);
                    }
                }
                topLevelElement = false;
            }
        }
Exemple #8
0
 protected static string FromXmlNmTokens(string nmTokens)
 {
     return(XmlCustomFormatter.FromXmlNmTokens(nmTokens));
 }
Exemple #9
0
 protected void WriteEmptyTag(string name, string ns)
 {
     name = XmlCustomFormatter.FromXmlName(name);
     WriteStartElement(name, ns);
     WriteEndElement();
 }
Exemple #10
0
 protected static string FromXmlNCName(string ncName)
 {
     return(XmlCustomFormatter.FromXmlNCName(ncName));
 }
Exemple #11
0
 protected static string FromTime(DateTime value)
 {
     return(XmlCustomFormatter.FromTime(value));
 }
Exemple #12
0
 protected static string FromEnum(long value, string[] values, long[] ids)
 {
     return(XmlCustomFormatter.FromEnum(value, values, ids));
 }
Exemple #13
0
 protected static string FromChar(char value)
 {
     return(XmlCustomFormatter.FromChar(value));
 }
Exemple #14
0
 protected static string FromByteArrayHex(byte[] value)
 {
     return(XmlCustomFormatter.FromByteArrayHex(value));
 }