<%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="Template description here." %> <%@ Property Name="ClassNamespace" Type="System.String" Optional="True" Category="Context" Description="The namespace that the generated class will be a member of." %> <%@ Property Name="ItemType" Type="System.String" Category="Context" Description="The type to use as an item in the collection." %> <%@ Property Name="ClassName" Type="System.String" Category="Context" Description="The name of the class to be generated." %> <%@ Property Name="Accessibility" Type="AccessibilityEnum" Category="Options" Description="The accessibility of the class to be generated." %> <%@ Property Name="GenerateDocumentation" Type="System.Boolean" Default="True" Category="Options" Description="Wether or not to include class documentation." %> using System; using System.Collections; <% if (ClassNamespace != null && ClassNamespace.Length > 0) { %> namespace <%= ClassNamespace %> { <% } %> <% if (GenerateDocumentation) { %> /// /// A strongly-typed collection of objects. /// <% } %> [Serializable] <%=GetAccessModifier(Accessibility)%> class <%= ClassName %> : CollectionBase { <% if (GenerateDocumentation) { %> /// /// Initializes a new instance of the <%= ClassName %> class /// that is empty and has the default initial capacity. /// <% } %> public <%= ClassName %>() { } <% if (GenerateDocumentation) { %> /// /// Initializes a new instance of the <%= ClassName %> class /// that contains elements copied from the specified <%= ClassName %>. /// /// The <%= ClassName %> whose elements are copied to the new collection. <% } %> public <%= ClassName %>(<%= ClassName %> c) { this.InnerList.AddRange(c); } <% if (GenerateDocumentation) { %> /// /// Gets or sets the at the specified index. /// /// The zero-based index of the element to get or set. /// /// is less than zero /// -or- /// is equal to or greater than . /// <% } %> public <%= ItemType %> this[int index] { get { return (<%= ItemType %>)List[index]; } set { List[index] = value; } } <% if (GenerateDocumentation) { %> /// /// Adds a to the end of the <%= ClassName %>. /// /// The to be added to the end of the <%= ClassName %>. /// The index at which the value has been added. <% } %> public virtual int Add(<%= ItemType %> item) { return List.Add(item); } <% if (GenerateDocumentation) { %> /// /// Inserts an element into the <%= ClassName %> at the specified index. /// /// The zero-based index at which should be inserted. /// The to insert. /// /// is less than zero /// -or- /// is equal to or greater than . /// <% } %> public virtual void Insert(int index, <%= ItemType %> item) { List.Insert(index, item); } <% if (GenerateDocumentation) { %> /// /// Removes the first occurrence of a specific from the <%= ClassName %>. /// /// The to remove from the <%= ClassName %>. /// /// The specified was not found in the <%= ClassName %>. /// <% } %> public virtual void Remove(<%= ItemType %> item) { List.Remove(item); } <% if (GenerateDocumentation) { %> /// /// Determines whether a given is in the <%= ClassName %>. /// /// The to check for. /// true if is found in the <%= ClassName %>; otherwise, false. <% } %> public bool Contains(<%= ItemType %> item) { return List.Contains(item); } <% if (GenerateDocumentation) { %> /// /// Returns the zero-based index of the first occurrence of a /// in the <%= ClassName %>. /// /// The to locate in the <%= ClassName %>. /// /// The zero-based index of the first occurrence of /// in the entire <%= ClassName %>, if found; otherwise, -1. /// <% } %> public int IndexOf(<%= ItemType %> item) { return List.IndexOf(item); } <% if (GenerateDocumentation) { %> /// /// Copies the entire <%= ClassName %> to a one-dimensional /// array. /// /// The one-dimensional array to copy to. /// The index in at which copying begins. <% } %> public void CopyTo(<%= ItemType %>[] array, int index) { List.CopyTo(array, index); } <% if (GenerateDocumentation) { %> /// /// Creates a read-only wrapper for a /// <%= ClassName %> instance. /// /// /// An <%= ClassName %> wrapper that is read-only. /// <% } %> public static <%= ClassName %> ReadOnly(<%= ClassName %> coll) { return new <%= ClassName %>.ReadOnly<%= ClassName %>(coll); } protected override void OnValidate(object value) { base.OnValidate(value); if (!(value is <%= ItemType %>)) { throw new ArgumentException("Collection only supports <%= ItemType %> objects."); } } #region ReadOnly<%= ClassName %> private sealed class ReadOnly<%= ClassName %> : <%= ClassName %> { private const string ERROR_STRING = "Collection is read-only."; internal ReadOnly<%= ClassName %>(<%= ClassName %> coll) : base(coll) { } public override int Add(<%= ItemType %> value) { throw new NotSupportedException(ERROR_STRING); } public override void Remove(<%= ItemType %> value) { throw new NotSupportedException(ERROR_STRING); } protected override void OnClear() { throw new NotSupportedException(ERROR_STRING); } protected override void OnInsert(int index, object value) { throw new NotSupportedException(ERROR_STRING); } protected override void OnRemove(int index, object value) { throw new NotSupportedException(ERROR_STRING); } protected override void OnSet(int index, object oldValue, object newValue) { throw new NotSupportedException(ERROR_STRING); } } #endregion } <% if (ClassNamespace != null && ClassNamespace.Length > 0) { %> } <% } %>