Esempio n. 1
0
        /// <summary>
        /// Reads properties of specified object.
        /// </summary>
        /// <param name="obj">The object to read.</param>
        /// <remarks>
        /// This method reads simple properties like "Text", "Border.Lines" etc. for specified object.
        /// To read nested properties like collections, you should override the <see cref="Base.DeserializeSubItems"/>
        /// method of an object.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public void ReadProperties(object obj)
        {
            if (props == null)
            {
                return;
            }

            // speed optimization, for use in the preview mode
            if (obj is TextObject && props.Length == 1 && props[0].Key == "x")
            {
                (obj as TextObject).Text = props[0].Value;
                return;
            }

            // Fix for multilevel properties with dots such Barcode.CalcCheckSum
            // Reported wrong working with saving from On-line Designer
            XmlProperty[] FProps0 = new XmlProperty[0];
            XmlProperty[] FProps1 = new XmlProperty[0];
            XmlProperty[] FProps2 = new XmlProperty[0];

            for (int i = 0; i < props.Length; i++)
            {
                int dotCount = getDotCount(props[i].Key);
                switch (dotCount)
                {
                case 0:
                    AppendProperty(ref FProps0, props[i]);
                    break;

                case 1:
                    AppendProperty(ref FProps1, props[i]);
                    break;

                default:
                    AppendProperty(ref FProps2, props[i]);
                    break;
                }
            }

            // without dots
            if (FProps0.Length > 0)
            {
                DoReadProperties(obj, FProps0);
            }
            // with one dot
            if (FProps1.Length > 0)
            {
                DoReadProperties(obj, FProps1);
            }
            // with two dots
            if (FProps2.Length > 0)
            {
                DoReadProperties(obj, FProps2);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the value for a specified property.
        /// </summary>
        /// <param name="key">The property name.</param>
        /// <param name="value">Value to set.</param>
        /// <remarks>
        /// For example, you have a node like <c>&lt;Node Text="" Left="0"/&gt;</c>. When you set the
        /// "Text" property to "test", the node will be <c>&lt;Node Text="test" Left="0"/&gt;</c>.
        /// If property with specified name is not exist, it will be added.
        /// </remarks>
        public void SetProp(string key, string value)
        {
            // property key should be trimmed
            key = key.Trim();

            if (properties == null)
            {
                properties    = new XmlProperty[1];
                properties[0] = XmlProperty.Create(key, value);
                return;
            }

            for (int i = 0; i < properties.Length; i++)
            {
                if (properties[i].Key == key)
                {
                    properties[i] = XmlProperty.Create(key, value);
                    return;
                }
            }

            Array.Resize <XmlProperty>(ref properties, properties.Length + 1);
            properties[properties.Length - 1] = XmlProperty.Create(key, value);
        }
Esempio n. 3
0
 private void AppendProperty(ref XmlProperty[] fProps, XmlProperty xmlProperty)
 {
     Array.Resize <XmlProperty>(ref fProps, fProps.Length + 1);
     fProps[fProps.Length - 1] = xmlProperty;
 }