예제 #1
0
        void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            if (Bits.EnabledCount == 0)
            {
                return;
            }

            Collections.IProtoEnum penum = GetProtoEnum(xs.Database);

            for (int x = 0; x < Bits.Count; x++)
            {
                if (Bits[x])
                {
                    using (s.EnterCursorBookmark(Params.ElementName))
                    {
                        string name = penum.GetMemberName(x);
                        Params.StreamDataName(s, FA.Write, ref name);
                    }
                }
            }
        }
        void WriteNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            if (Bits.EnabledCount == 0)
            {
                return;
            }

            var xs = s.GetSerializerInterface();

            Collections.IProtoEnum penum = GetProtoEnum(xs.Database);

            if (Bits.Params.kGetMemberDefaultValue != null)
            {
                Contract.Assert(Params.ElementItselfMeansTrue);
                WriteNodesNotEqualToDefaultValues(s, penum);
                return;
            }

            foreach (var bitIndex in Bits.RawBits.SetBitIndices)
            {
                string name = penum.GetMemberName(bitIndex);

                if (Params.ElementItselfMeansTrue)
                {
                    using (s.EnterCursorBookmark(name))
                    {
                        // do nothing
                    }
                }
                else
                {
                    using (s.EnterCursorBookmark(Params.ElementName))
                    {
                        Params.StreamDataName(s, ref name);
                    }
                }
            }
        }
        void WriteNodesNotEqualToDefaultValues <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, Collections.IProtoEnum penum)
            where TDoc : class
            where TCursor : class
        {
            var getDefault = Bits.Params.kGetMemberDefaultValue;

            for (int x = 0; x < penum.MemberCount; x++)
            {
                bool bitDefault = getDefault(x);
                if (bitDefault == Bits[x])
                {
                    continue;
                }

                string name = penum.GetMemberName(x);
                using (s.EnterCursorBookmark(name))
                {
                    bool writtenValue = !bitDefault;
                    s.WriteCursor(writtenValue);
                }
            }
        }