Exemplo n.º 1
0
        public void SetPropertiesInstance(System.Xml.XmlNode node, object inst)
        {
            node.RemoveAll();       // Get rid of all properties

            BarCodePropertiesQR bcp = inst as BarCodePropertiesQR;
            if (bcp == null)
                return;

            XmlHelpers.CreateChild(node, "QrCode", bcp.QrCode);
        }
Exemplo n.º 2
0
        public void ProcessMultipleNodes(XmlReader reader, Action<string> setter, string languageRequired = null)
        {
            /*
            <category lang="en">Property - English</category>
		    <category lang="en">Property - English 2</category>
		    <category lang="es">Property - Spanish</category>
		    <category lang="es">Property - Spanish 2</category>
		    <category lang="">Property - Empty Language</category>
		    <category lang="">Property - Empty Language 2</category>
		    <category>Property - No Language</category>
		    <category>Property - No Language 2</category>
            */

            /*  Expected Behaviour:
                - Language = Null   Property - No Language / Property - No Language 2
                - Language = ""     Property - Empty Language / Property - Empty Language 2
                - Language = es     Property - Spanish / Property - Spanish 2
                - Language = en     Property - English / Property - English 2
            */

            var currentElementName = reader.Name;
            var values = new[] { new { Language = reader.GetAttribute("lang"), Value = reader.ReadElementContentAsString() } }.ToList();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name != currentElementName)
                {
                    break;
                }

                if (reader.NodeType == XmlNodeType.Element && reader.Name == currentElementName)
                {
                    values.Add(new { Language = reader.GetAttribute("lang"), Value = reader.ReadElementContentAsString() });
                }
            }

            if (values.Count(v => v.Language == languageRequired) > 0)
            {
                values.RemoveAll(v => v.Language != languageRequired);
            }

            // ENumerate and return all the matches
            foreach (var result in values)
            {
                setter(result.Value);
            }
        }