Svg.SvgElementIdManager.AddAndForceUniqueID C# (CSharp) Method

AddAndForceUniqueID() public method

Adds the specified SvgElement for ID management. And can auto fix the ID if it already exists or it starts with a number.
public AddAndForceUniqueID ( SvgElement element, SvgElement sibling, bool autoForceUniqueID = true, Action logElementOldIDNewID = null ) : bool
element SvgElement The to be managed.
sibling SvgElement
autoForceUniqueID bool Pass true here, if you want the ID to be fixed
logElementOldIDNewID Action If not null, the action is called before the id is fixed
return bool
        public virtual bool AddAndForceUniqueID(SvgElement element, SvgElement sibling, bool autoForceUniqueID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
        {
            var result = false;
            if (!string.IsNullOrEmpty(element.ID))
            {
                var newID = this.EnsureValidId(element.ID, autoForceUniqueID);
                if (autoForceUniqueID && newID != element.ID)
                {
                    if(logElementOldIDNewID != null)
                        logElementOldIDNewID(element, element.ID, newID);
                    element.ForceUniqueID(newID);
                    result = true;
                }
                this._idValueMap.Add(element.ID, element);
            }
            
            OnAdded(element);
            return result;
        }