internal DomAttribute AttributeByNameOrCreate(DomName name, bool insertFirst = false)
        {
            var attr = Attributes[name];

            if (attr == null)
            {
                // Owner doc could be null (rare)
                var doc = OwnerDocument;
                if (doc == null)
                {
                    attr = DomProviderFactory.ForProviderObject(this).CreateNodeFactory(null).CreateAttribute(name);
                }
                else
                {
                    attr = doc.CreateAttribute(name);
                }
                if (insertFirst)
                {
                    Attributes.Insert(0, attr);
                }
                else
                {
                    Attributes.Add(attr);
                }
            }
            return(attr);
        }
        public DomElement Element(DomName name)
        {
            CheckName(name);
            IEqualityComparer <DomName> comparer = NameContext;

            return(Elements.FirstOrDefault(t => comparer.Equals(t.Name, name)));
        }
Exemple #3
0
 protected virtual DomAttribute CreateAttributeCore(DomName name)
 {
     return(ApplyNameContext(
                this,
                ApplySchema(NodeFactory.CreateAttribute(name) ?? new DomAttribute(name))
                ));
 }
Exemple #4
0
        public DomAttribute CreateAttribute(DomName name, string value)
        {
            var result = CreateAttribute(name);

            result.Value = value;
            return(result);
        }
Exemple #5
0
 protected virtual DomElement CreateElementCore(DomName name)
 {
     return(ApplyNameContext(
                this,
                ApplySchema(NodeFactory.CreateElement(name) ?? new DomElement(name))
                ));
 }
        public DomElement PrependElement(DomName name)
        {
            var e = OwnerDocumentOrSelf.CreateElement(name);

            Prepend(e);
            return(e);
        }
Exemple #7
0
 public DomPath Element(DomName name)
 {
     if (name is null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(Append(DomPathExpression.Element(name, -1)));
 }
Exemple #8
0
 protected internal DomElement()
 {
     _name = CheckName(RequireFactoryGeneratedName(
                           GetType(),
                           (e, t) => e.GetElementName(t)
                           ));
     _attributes = new DomAttributeCollectionApi(this);
 }
 protected DomNodeDefinition(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     Name = name;
 }
Exemple #10
0
 public DomNode RemoveAttribute(DomName name)
 {
     if (HasAttributes)
     {
         Attributes.Remove(name);
     }
     return(this);
 }
 public string Attribute(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(QueryFirstOrDefault(n => n.Attribute(name)));
 }
        public T AddNew(DomName name)
        {
            ThrowIfReadOnly();
            var result = _ctor(name);

            Add(result);
            return(result);
        }
Exemple #13
0
 internal static DomName RequireName(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(name);
 }
Exemple #14
0
 protected internal DomAttribute()
 {
     _name = CheckName(RequireFactoryGeneratedName(
                           GetType(),
                           (e, t) => e.GetAttributeName(t)
                           ));
     this.content = Dom.DomValue.Create();
 }
Exemple #15
0
 public virtual DomAttribute CreateAttribute(DomName name)
 {
     return(CreateNode(
                GetAttributeNodeType(name),
                name,
                nameOrTarget => new DomAttribute(nameOrTarget)
                ));
 }
Exemple #16
0
 public virtual DomElement CreateElement(DomName name)
 {
     return(CreateNode(
                GetElementNodeType(name),
                name,
                nameOrTarget => new DomElement(nameOrTarget)
                ));
 }
Exemple #17
0
        protected override DomObject SetNameCore(DomName name)
        {
            var newAttr = OwnerDocument.CreateAttribute(name);

            newAttr.DomValue = DomValue.Clone();
            newAttr.CopyAnnotationsFrom(AnnotationList);
            return(ReplaceWith(newAttr));
        }
Exemple #18
0
            public override int GetHashCode(DomName obj)
            {
                int hashCode = -1450740237;

                hashCode = hashCode * -1521134295 + obj.NamespaceUri.GetHashCode();
                hashCode = hashCode * -1521134295 + obj.LocalName.GetHashCode();
                return(hashCode);
            }
Exemple #19
0
 public static DomElementCollection Elements(this DomContainer source, DomName name)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     return(new DefaultDomElementCollection(source, s => FilterByName(s.Elements, name)));
 }
Exemple #20
0
 public static DomElementCollection FollowingSiblings(this DomElement source, DomName name)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     return(new DefaultDomElementCollection(source, s => FilterByName(((DomElement)s).FollowingSiblings, name)));
 }
Exemple #21
0
 private T CreateNode <T>(Type type, DomName name, Func <DomName, T> ctor)
 {
     if (type == typeof(T) || type == null)
     {
         return(ctor(name));
     }
     return((T)CtorInfo(type).Invoke(name));
 }
 public DescendantHasAttributeValueExpr(DomName name, string value)
 {
     if (value[0] == '"')
     {
         throw new ArgumentException();
     }
     _name  = name;
     _value = value;
 }
 private bool ParseName(out DomName name)
 {
     name = DomName.Create(Current.Value);
     if (Current.Type == TokenType.String)
     {
         return(MoveNext());
     }
     return(false);
 }
Exemple #24
0
        protected override DomObject SetNameCore(DomName name)
        {
            var newElement = OwnerDocument.CreateElement(name);

            newElement.Append(ChildNodes.ToList());
            newElement.Attributes.AddRange(Attributes.ToList());
            newElement.CopyAnnotationsFrom(AnnotationList);
            return(ReplaceWith(newElement));
        }
Exemple #25
0
 protected internal DomAttribute(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     _name        = name;
     this.content = Dom.DomValue.Create();
 }
Exemple #26
0
        public override void WriteStartElement(DomName name)
        {
            _state.StartElement();
            ImpliesElementWithChildNodes();

            var element = new DomElementState(name.LocalName);

            _elements.Push(element);
        }
Exemple #27
0
            public override int Compare(DomName x, DomName y)
            {
                int result = _namespaceComparer.Compare(x.Namespace, y.Namespace);

                if (result != 0)
                {
                    return(result);
                }
                return(_localNameComparer.Compare(x.LocalName, y.LocalName));
            }
Exemple #28
0
            public override int Compare(DomName x, DomName y)
            {
                int result = StringComparer.Ordinal.Compare(x.NamespaceUri, y.NamespaceUri);

                if (result == 0)
                {
                    result = StringComparer.Ordinal.Compare(x.LocalName, y.LocalName);
                }
                return(result);
            }
        public TValue Attribute <TValue>(DomName name)
        {
            var attr = Attributes[name];

            if (attr == null)
            {
                return(default(TValue));
            }
            return(attr.GetValue <TValue>());
        }
Exemple #30
0
        public Type GetAttributeNodeType(DomName name)
        {
            var  attr   = AttributeDefinitions[name];
            Type result = null;

            if (attr != null)
            {
                result = attr.AttributeNodeType;
            }
            return(result ?? NodeTypeProvider.GetAttributeNodeType(name));
        }