Esempio n. 1
0
        /// <summary>
        /// Serialize XmlQueryStaticData object into a byte array.
        /// </summary>
        public void GetObjectData(out byte[] data, out Type[] ebTypes)
        {
            MemoryStream       dataStream = new MemoryStream(4096);
            XmlQueryDataWriter dataWriter = new XmlQueryDataWriter(dataStream);

            // First put the format version
            dataWriter.Write7BitEncodedInt(CurrentFormatVersion);

            // XmlWriterSettings defaultWriterSettings;
            _defaultWriterSettings.GetObjectData(dataWriter);

            // IList<WhitespaceRule> whitespaceRules;
            if (_whitespaceRules == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_whitespaceRules.Count);
                foreach (WhitespaceRule rule in _whitespaceRules)
                {
                    rule.GetObjectData(dataWriter);
                }
            }

            // string[] names;
            if (_names == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_names.Length);
                foreach (string name in _names)
                {
                    dataWriter.Write(name);
                }
            }

            // StringPair[][] prefixMappingsList;
            if (_prefixMappingsList == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_prefixMappingsList.Length);
                foreach (StringPair[] mappings in _prefixMappingsList)
                {
                    dataWriter.Write(mappings.Length);
                    foreach (StringPair mapping in mappings)
                    {
                        dataWriter.Write(mapping.Left);
                        dataWriter.Write(mapping.Right);
                    }
                }
            }

            // Int32Pair[] filters;
            if (_filters == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_filters.Length);
                foreach (Int32Pair filter in _filters)
                {
                    dataWriter.Write7BitEncodedInt(filter.Left);
                    dataWriter.Write7BitEncodedInt(filter.Right);
                }
            }

            // XmlQueryType[] types;
            if (_types == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_types.Length);
                foreach (XmlQueryType type in _types)
                {
                    XmlQueryTypeFactory.Serialize(dataWriter, type);
                }
            }

            // XmlCollation[] collations;
            if (_collations == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_collations.Length);
                foreach (XmlCollation collation in _collations)
                {
                    collation.GetObjectData(dataWriter);
                }
            }

            // string[] globalNames;
            if (_globalNames == null)
            {
                dataWriter.Write(0);
            }
            else
            {
                dataWriter.Write(_globalNames.Length);
                foreach (string name in _globalNames)
                {
                    dataWriter.Write(name);
                }
            }

            // EarlyBoundInfo[] earlyBound;
            if (_earlyBound == null)
            {
                dataWriter.Write(0);
                ebTypes = null;
            }
            else
            {
                dataWriter.Write(_earlyBound.Length);
                ebTypes = new Type[_earlyBound.Length];
                int idx = 0;
                foreach (EarlyBoundInfo info in _earlyBound)
                {
                    dataWriter.Write(info.NamespaceUri);
                    ebTypes[idx++] = info.EarlyBoundType;
                }
            }

            dataWriter.Dispose();
            data = dataStream.ToArray();
        }