Class TagCollection
- Namespace
- Dynamicweb.Rendering
- Assembly
- Dynamicweb.Core.dll
Represents a collection of Tag.
[Serializable]
public class TagCollection : KeyedCollection<string, Tag>, IList<Tag>, ICollection<Tag>, IReadOnlyList<Tag>, IReadOnlyCollection<Tag>, IEnumerable<Tag>, IList, ICollection, IEnumerable
- Inheritance
-
TagCollection
- Implements
- Inherited Members
- Extension Methods
Examples
using Dynamicweb.Rendering;
namespace Dynamicweb.Examples.Rendering
{
public class TagSample
{
public static void AddTags(Template template)
{
//Create a tag instance and add it to a template instance
var myTag = new Tag("greeting", "Hello");
template.Tags.Add(myTag);
//Create a second tag instance using its Name and Value properties and add it to a template instance
var myTag2 = new Tag();
myTag2.Name = "greeting2";
myTag2.Value = " World!";
template.Tags.Add(myTag2);
//Create a collection of tags and add it to a template instance
var myTags = new TagCollection();
for (int i = 1; i <= 5; i++)
{
myTags.Add(new Tag("Counter" + i.ToString(), i.ToString()));
}
template.Tags.Add(myTags);
//Examine all the tags in the template instance.
foreach (Tag tag in template.Tags)
{
if (tag.Name == "greeting")
{
//Found the tag in the collection named "greeting"
}
}
//Or look it up
if (template.Tags.ContainsTagName("greeting"))
{
//Found the tag in the collection named "greeting"
}
//And clear all tags from the template instances tags collection
template.Tags.Clear();
}
}
}
Constructors
TagCollection()
Initializes a new instance of the TagCollection class.
public TagCollection()
Examples
See usage example in TagCollection
Methods
Add(Tag)
Adds the specified tag.
public void Add(Tag tag)
Parameters
tag
TagThe tag of the tag.
Examples
See usage example in TagCollection
Remarks
If a tag with the same name already exists, the tag is not inserted.
Add(TagCollection)
Adds the specified collection of tags to this instance of the collection.
public void Add(TagCollection tags)
Parameters
tags
TagCollectionThe collection of tags to add to this instance.
Examples
See usage example in TagCollection
Remarks
If a tag with the same name already exists, the tag is not inserted.
ContainsTagName(string)
Determines whether the collection contains a tag with the specified name.
public bool ContainsTagName(string name)
Parameters
name
stringThe name of the tag.
Returns
- bool
true
if the specified name is found; otherwise,false
.
Examples
See usage example in TagCollection
GetKeyForItem(Tag)
Gets the key for item. The key is the tag name.
protected override string GetKeyForItem(Tag item)
Parameters
Returns
GetTagByName(string)
Gets the tag object by tag name.
public Tag? GetTagByName(string name)
Parameters
name
stringThe name of the tag.
Returns
- Tag
A Tag instance if the collection contains a tag with the specified name, otherwise
null
(Nothing
in Visual Basic)
Examples
See usage example in TagCollection