Пример #1
0
        public static bool StreamBVector <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s
                                                         , string xmlName, ref BVector vector
                                                         , bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName));

            string     string_value = null;
            bool       was_streamed = true;
            const bool to_lower     = false;

            if (s.IsReading)
            {
                if (isOptional)
                {
                    was_streamed = s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource);
                }
                else
                {
                    s.StreamString(xmlName, ref string_value, to_lower, xmlSource);
                }

                if (was_streamed)
                {
                    var parse_result = PhxUtil.ParseBVectorString(string_value);
                    if (!parse_result.HasValue)
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException(string.Format(
                                                                                    "Failed to parse value (hint: {0}) as vector: {1}",
                                                                                    xmlSource.RequiresName() ? xmlName : "ElementText",
                                                                                    string_value)));
                    }

                    vector = parse_result.Value;
                }
            }
            else if (s.IsWriting)
            {
                if (isOptional && PhxPredicates.IsZero(vector))
                {
                    was_streamed = false;
                    return(was_streamed);
                }

                string_value = vector.ToBVectorString();

                if (isOptional)
                {
                    s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource);
                }
                else
                {
                    s.StreamString(xmlName, ref string_value, to_lower, xmlSource);
                }
            }

            return(was_streamed);
        }
Пример #2
0
        public static bool StreamIntegerColor <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s
                                                              , string xmlName, ref System.Drawing.Color color
                                                              , byte defaultAlpha = 0xFF
                                                              , bool isOptional   = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName));

            string     string_value = null;
            bool       was_streamed = true;
            const bool to_lower     = false;

            if (s.IsReading)
            {
                if (isOptional)
                {
                    was_streamed = s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource);
                }
                else
                {
                    s.StreamString(xmlName, ref string_value, to_lower, xmlSource);
                }

                if (was_streamed)
                {
                    if (!PhxUtil.TokenizeIntegerColor(string_value, defaultAlpha, ref color))
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException(string.Format(
                                                                                    "Failed to parse value (hint: {0}) as color: {1}",
                                                                                    xmlSource.RequiresName() ? xmlName : "ElementText",
                                                                                    string_value)));
                    }
                }
            }
            else if (s.IsWriting)
            {
                if (isOptional && PhxPredicates.IsZero(color))
                {
                    was_streamed = false;
                    return(was_streamed);
                }

                string_value = color.ToIntegerColorString(defaultAlpha);

                if (isOptional)
                {
                    s.StreamStringOpt(xmlName, ref string_value, to_lower, xmlSource);
                }
                else
                {
                    s.StreamString(xmlName, ref string_value, to_lower, xmlSource);
                }
            }

            return(was_streamed);
        }