Пример #1
0
        private void DomNode_AttributeChanged(object sender, AttributeEventArgs e)
        {
            if (e.DomNode == this.DomNode)
            {
                return;
            }

            if (!e.AttributeInfo.Equivalent(e.DomNode.Type.IdAttribute))
            {
                string originalName;
                if (m_intsToOriginal.TryGetValue(e.DomNode, out originalName))
                {
                    ObjectOverride objectOverride;
                    m_overridesMap.TryGetValue(originalName, out objectOverride);
                    if (objectOverride == null)
                    {
                        objectOverride = ObjectOverride.Create(originalName);
                        m_overrideList.Add(objectOverride);
                        m_overridesMap.Add(originalName, objectOverride);
                    }

                    AttributeOverride attrOverride = objectOverride.GetOrCreateByName(e.AttributeInfo.Name);
                    attrOverride.AttribValue = e.AttributeInfo.Type.Convert(e.NewValue);
                }
            }
        }
Пример #2
0
        public static AttributeOverride Create(string name, string value)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new InvalidOperationException("name cannot be null or empty");
            }

            DomNode           node         = new DomNode(Schema.attributeOverrideType.Type);
            AttributeOverride attrOverride = node.As <AttributeOverride>();

            attrOverride.Name        = name;
            attrOverride.AttribValue = value;
            return(attrOverride);
        }
Пример #3
0
        /// <summary>
        /// Gets AttributeOverride by name
        /// if not found then it will create new instacne</summary>
        public AttributeOverride GetOrCreateByName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new InvalidOperationException("name cannot be null or empty");
            }

            //note:linear search is OK there are not many items.
            // find AttributeOverride by name.
            foreach (var attrib in m_overrides)
            {
                if (attrib.Name == name)
                {
                    return(attrib);
                }
            }

            // if not found  create new instance and add it to the list.
            AttributeOverride attrOverride = AttributeOverride.Create(name, "");

            m_overrides.Add(attrOverride);
            return(attrOverride);
        }