Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public DomElement Element(DomName name)
        {
            CheckName(name);
            IEqualityComparer <DomName> comparer = NameContext;

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

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

            Prepend(e);
            return(e);
        }
Exemplo n.º 7
0
 public DomPath Element(DomName name)
 {
     if (name is null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(Append(DomPathExpression.Element(name, -1)));
 }
Exemplo n.º 8
0
 protected internal DomElement()
 {
     _name = CheckName(RequireFactoryGeneratedName(
                           GetType(),
                           (e, t) => e.GetElementName(t)
                           ));
     _attributes = new DomAttributeCollectionApi(this);
 }
Exemplo n.º 9
0
 protected DomNodeDefinition(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     Name = name;
 }
Exemplo n.º 10
0
 public DomNode RemoveAttribute(DomName name)
 {
     if (HasAttributes)
     {
         Attributes.Remove(name);
     }
     return(this);
 }
Exemplo n.º 11
0
 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);
        }
Exemplo n.º 13
0
 internal static DomName RequireName(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(name);
 }
Exemplo n.º 14
0
 protected internal DomAttribute()
 {
     _name = CheckName(RequireFactoryGeneratedName(
                           GetType(),
                           (e, t) => e.GetAttributeName(t)
                           ));
     this.content = Dom.DomValue.Create();
 }
Exemplo n.º 15
0
 public virtual DomAttribute CreateAttribute(DomName name)
 {
     return(CreateNode(
                GetAttributeNodeType(name),
                name,
                nameOrTarget => new DomAttribute(nameOrTarget)
                ));
 }
Exemplo n.º 16
0
 public virtual DomElement CreateElement(DomName name)
 {
     return(CreateNode(
                GetElementNodeType(name),
                name,
                nameOrTarget => new DomElement(nameOrTarget)
                ));
 }
Exemplo n.º 17
0
        protected override DomObject SetNameCore(DomName name)
        {
            var newAttr = OwnerDocument.CreateAttribute(name);

            newAttr.DomValue = DomValue.Clone();
            newAttr.CopyAnnotationsFrom(AnnotationList);
            return(ReplaceWith(newAttr));
        }
Exemplo n.º 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);
            }
Exemplo n.º 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)));
 }
Exemplo n.º 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)));
 }
Exemplo n.º 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));
 }
Exemplo n.º 22
0
 public DescendantHasAttributeValueExpr(DomName name, string value)
 {
     if (value[0] == '"')
     {
         throw new ArgumentException();
     }
     _name  = name;
     _value = value;
 }
Exemplo n.º 23
0
 private bool ParseName(out DomName name)
 {
     name = DomName.Create(Current.Value);
     if (Current.Type == TokenType.String)
     {
         return(MoveNext());
     }
     return(false);
 }
Exemplo n.º 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));
        }
Exemplo n.º 25
0
 protected internal DomAttribute(DomName name)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     _name        = name;
     this.content = Dom.DomValue.Create();
 }
Exemplo n.º 26
0
        public override void WriteStartElement(DomName name)
        {
            _state.StartElement();
            ImpliesElementWithChildNodes();

            var element = new DomElementState(name.LocalName);

            _elements.Push(element);
        }
Exemplo n.º 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));
            }
Exemplo n.º 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);
            }
Exemplo n.º 29
0
        public TValue Attribute <TValue>(DomName name)
        {
            var attr = Attributes[name];

            if (attr == null)
            {
                return(default(TValue));
            }
            return(attr.GetValue <TValue>());
        }
Exemplo n.º 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));
        }