Пример #1
0
 protected static string ToXmlNmTokens(string value)
 {
     return(XmlCustomFormatter.ToXmlNmTokens(value));
 }
Пример #2
0
 protected static DateTime ToTime(string value)
 {
     return(XmlCustomFormatter.ToTime(value));
 }
Пример #3
0
 protected static string ToXmlNCName(string value)
 {
     return(XmlCustomFormatter.ToXmlNCName(value));
 }
Пример #4
0
 protected static char ToChar(string value)
 {
     return(XmlCustomFormatter.ToChar(value));
 }
Пример #5
0
 protected static long ToEnum(string value, Hashtable h, string typeName)
 {
     return(XmlCustomFormatter.ToEnum(value, h, typeName, true));
 }
Пример #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();
        }
Пример #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;
            }
        }
Пример #8
0
 protected static string FromXmlNmTokens(string nmTokens)
 {
     return(XmlCustomFormatter.FromXmlNmTokens(nmTokens));
 }
Пример #9
0
 protected void WriteEmptyTag(string name, string ns)
 {
     name = XmlCustomFormatter.FromXmlName(name);
     WriteStartElement(name, ns);
     WriteEndElement();
 }
Пример #10
0
 protected static string FromXmlNCName(string ncName)
 {
     return(XmlCustomFormatter.FromXmlNCName(ncName));
 }
Пример #11
0
 protected static string FromTime(DateTime value)
 {
     return(XmlCustomFormatter.FromTime(value));
 }
Пример #12
0
 protected static string FromEnum(long value, string[] values, long[] ids)
 {
     return(XmlCustomFormatter.FromEnum(value, values, ids));
 }
Пример #13
0
 protected static string FromChar(char value)
 {
     return(XmlCustomFormatter.FromChar(value));
 }
Пример #14
0
 protected static string FromByteArrayHex(byte[] value)
 {
     return(XmlCustomFormatter.FromByteArrayHex(value));
 }