Esempio n. 1
0
        /// <summary>
        /// Adds the specified <see cref="SvgElement"/> for ID management. 
        /// And can auto fix the ID if it already exists or it starts with a number.
        /// </summary>
        /// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
        /// <param name="autoFixID">Pass true here, if you want the ID to be fixed</param>
        /// <param name="logElementOldIDNewID">If not null, the action is called before the id is fixed</param>
        /// <returns>true, if ID was altered</returns>
        public virtual bool AddAndFixID(SvgElement element, bool autoFixID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
        {
            var result = false;
            if (!string.IsNullOrEmpty(element.ID))
            {
                var newID = this.EnsureValidId(element.ID, autoFixID);
                if (autoFixID && newID != element.ID)
                {
                    if(logElementOldIDNewID != null)
                        logElementOldIDNewID(element, element.ID, newID);
                    element.FixID(newID);
                    result = true;
                }
                this._idValueMap.Add(element.ID, element);
            }

            OnAdded(element);
            return result;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the specified <see cref="SvgElement"/> for ID management.
        /// And can auto fix the ID if it already exists or it starts with a number.
        /// </summary>
        /// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
        /// <param name="autoFixID">Pass true here, if you want the ID to be fixed</param>
        /// <param name="logElementOldIDNewID">If not null, the action is called before the id is fixed</param>
        /// <returns>true, if ID was altered</returns>
        public virtual bool AddAndFixID(SvgElement element, bool autoFixID = true, Action <SvgElement, string, string> logElementOldIDNewID = null)
        {
            var result = false;

            if (!string.IsNullOrEmpty(element.ID))
            {
                var newID = this.EnsureValidId(element.ID, autoFixID);
                if (autoFixID && newID != element.ID)
                {
                    if (logElementOldIDNewID != null)
                    {
                        logElementOldIDNewID(element, element.ID, newID);
                    }
                    element.FixID(newID);
                    result = true;
                }
                this._idValueMap.Add(element.ID, element);
            }

            OnAdded(element);
            return(result);
        }