public void IndexByAllNames() { NodeFieldReferenceCollection nodes = new NodeFieldReferenceCollection(); hibernatemapping hm = new hibernatemapping(); NodeFieldReference field = new NodeFieldReference(hm, typeof(hibernatemapping).GetField("Items"), new SchemaEditorNodeTestFactory(), new SchemaEditorTestNode("blah", null, null)); nodes.Add(field); Assert.AreSame(field,nodes[typeof(@class)]); Assert.AreSame(field,nodes[typeof(@joinedsubclass)]); }
public SchemaEditorTestNode(string name, object val, NodeFieldReference fieldReference) { this.activeAttributes = new FieldReferenceCollection(); this.attributes = new FieldReferenceCollection(); this.nodeFields = new NodeFieldReferenceCollection(); this.activeNodes = new SchemaEditorNodeCollection(); this.fieldReference = fieldReference; this.name = name; this.val = val; this.attributesReadOnly = FieldReferenceCollection.ReadOnly(attributes); this.activeAttributesReadOnly = FieldReferenceCollection.ReadOnly(activeAttributes); this.activeNodesReadOnly = SchemaEditorNodeCollection.ReadOnly(activeNodes); this.nodeFieldsReadOnly = NodeFieldReferenceCollection.ReadOnly(nodeFields); }
public WinFormsSchemaEditorNode(SchemaEditorView view, NodeFieldReference fieldReference, object val, string name) { this.activeAttributes = new FieldReferenceCollection(); this.attributes = new FieldReferenceCollection(); this.nodeFields = new NodeFieldReferenceCollection(); this.activeNodes = new SchemaEditorNodeCollection(); this.fieldReference = fieldReference; this.view = view; this.val = val; this.attributesReadOnly = FieldReferenceCollection.ReadOnly(attributes); this.activeAttributesReadOnly = FieldReferenceCollection.ReadOnly(activeAttributes); this.activeNodesReadOnly = SchemaEditorNodeCollection.ReadOnly(activeNodes); this.nodeFieldsReadOnly = NodeFieldReferenceCollection.ReadOnly(nodeFields); this.nodeName = name; RefreshTitle(); }
/// <summary> /// Adds a <see cref="NodeFieldReference"/> to the end /// of the <see cref="NodeFieldReferenceCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to be added /// to the end of the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The <see cref="NodeFieldReferenceCollection"/> /// index at which the <paramref name="value"/> has been added. /// </returns> /// <exception cref="NotSupportedException"><para> /// The <see cref="NodeFieldReferenceCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>NodeFieldReferenceCollection</b> /// already contains <paramref name="value"/>, /// and the <b>NodeFieldReferenceCollection</b> /// ensures that all elements are unique.</para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Add"/> for details. /// </remarks> public virtual int Add(NodeFieldReference value) { if (_data.IsUnique) CheckUnique(value); int count = _data.Count; if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); _data.Items[count] = value; return _data.Count++; }
/// <summary> /// Create a node that is an active node of the parent node and that contains the obj /// as the internal value. /// </summary> /// <returns>The newly created node, already registered as an active node of the parent node.</returns> public ISchemaEditorNode CreateNode(NodeFieldReference fieldReference, object obj, string name) { ISchemaEditorNode child = new SchemaEditorTestNode(name, obj, fieldReference); return child; }
/// <summary> /// Add a node's field to the <see cref="ISchemaEditorNode.NodeFields"/> collection /// </summary> /// <param name="fieldReference">The parameter to add</param> public void AddNodeField(NodeFieldReference fieldReference) { nodeFields.Add(fieldReference); }
private static ISchemaEditorNode AddActiveChildNode(ISchemaEditorNode parentNode, NodeFieldReference fieldReference, object fieldValue, ISchemaEditorNodeFactory factory) { ISchemaEditorNode child = fieldReference.AddExistingValue(fieldValue); BuildNodeState(child, factory); return child; }
/// <overloads> /// Copies the <see cref="NodeFieldReferenceCollection"/> /// or a portion of it to a one-dimensional array. /// </overloads> /// <summary> /// Copies the entire <see cref="NodeFieldReferenceCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="NodeFieldReference"/> elements, /// starting at the beginning of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="NodeFieldReference"/> elements copied from the /// <see cref="NodeFieldReferenceCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// The number of elements in the source /// <see cref="NodeFieldReferenceCollection"/> is greater than /// the available space in the destination <paramref name="array"/>. /// </exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(NodeFieldReference[] array) { ((ICollection) this).CopyTo(array, 0); }
/// <summary> /// Searches a section of the sorted /// <see cref="NodeFieldReferenceCollection"/> for an /// <see cref="NodeFieldReference"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="index"> /// The zero-based starting index of the range of elements to search. /// </param> /// <param name="count">The number of elements to search.</param> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to locate /// in the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="NodeFieldReferenceCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"><para> /// <paramref name="index"/> and <paramref name="count"/> /// do not denote a valid range of elements in the /// <see cref="NodeFieldReferenceCollection"/>. /// </para><para>-or-</para><para> /// <paramref name="comparer"/> is a null reference, /// and NodeFieldReference does not implement /// the <see cref="IComparable"/> interface. /// </para></exception> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para> /// <para><paramref name="count"/> is less than zero.</para> /// </exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Int32, Int32, Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch(int index, int count, NodeFieldReference value, IComparer comparer) { if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (count < 0) throw new ArgumentOutOfRangeException("count", count, "Argument cannot be negative."); if (index + count > _data.Count) throw new ArgumentException("Arguments denote invalid range of elements."); return Array.BinarySearch(_data.Items, index, _data.Count, value, comparer); }
private void CheckUnique(NodeFieldReference value) { if (IndexOf(value) >= 0) throw new NotSupportedException("Unique collections cannot contain duplicate elements."); }
private void AddRange(NodeFieldReference[] array, int range) { if (range == 0) return; if (_data.IsUnique) { foreach (NodeFieldReference value in array) CheckUnique(value); } if (_data.Count + range > _data.Items.Length) _data.EnsureCapacity(_data.Count + range); Array.Copy(array, 0, _data.Items, _data.Count, range); _data.Count += range; }
/// <summary> /// Copies the elements of the <see cref="NodeFieldReferenceCollection"/> /// to a new <see cref="Array"/> of /// <see cref="NodeFieldReference"/> elements. /// </summary> /// <returns> /// A one-dimensional <see cref="Array"/> of /// <see cref="NodeFieldReference"/> elements containing copies of the /// elements of the <see cref="NodeFieldReferenceCollection"/>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.ToArray"/> for details. /// </remarks> public NodeFieldReference[] ToArray() { NodeFieldReference[] array = new NodeFieldReference[_data.Count]; Array.Copy(_data.Items, array, _data.Count); return array; }
/// <summary> /// Removes the first occurrence of the specified /// <see cref="NodeFieldReference"/> from the /// <see cref="NodeFieldReferenceCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to remove /// from the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="NotSupportedException"> /// The <see cref="NodeFieldReferenceCollection"/> /// is read-only or has a fixed size.</exception> /// <remarks> /// Please refer to <see cref="ArrayList.Remove"/> for details. /// </remarks> public void Remove(NodeFieldReference value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); }
/// <summary> /// Inserts a <see cref="NodeFieldReference"/> element into the /// <see cref="NodeFieldReferenceCollection"/> at the specified index. /// </summary> /// <param name="index"> /// The zero-based index at which <paramref name="value"/> /// should be inserted.</param> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to insert /// into the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero.</para> /// <para>-or-</para><para> /// <paramref name="index"/> is greater than <see cref="Count"/>. /// </para></exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="NodeFieldReferenceCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>NodeFieldReferenceCollection</b> /// already contains <paramref name="value"/>, /// and the <b>NodeFieldReferenceCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.Insert"/> for details. /// </remarks> public virtual void Insert(int index, NodeFieldReference value) { int count = _data.Count; if (index < 0) throw new ArgumentOutOfRangeException("index", index, "Argument cannot be negative."); if (index > count) throw new ArgumentOutOfRangeException("index", index, "Argument cannot exceed Count."); if (_data.IsUnique) CheckUnique(value); if (count == _data.Items.Length) _data.EnsureCapacity(count + 1); if (index < count) Array.Copy(_data.Items, index, _data.Items, index + 1, count - index); _data.Items[index] = value; _data.Count++; }
/// <summary> /// Returns the zero-based index of the first occurrence /// of the specified <see cref="NodeFieldReference"/> in the /// <see cref="NodeFieldReferenceCollection"/>. /// </summary> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object /// to locate in the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// The zero-based index of the first occurrence of /// <paramref name="value"/> in the <see cref="NodeFieldReferenceCollection"/>, /// if found; otherwise, -1.</returns> /// <remarks> /// Please refer to <see cref="ArrayList.IndexOf"/> for details. /// </remarks> public int IndexOf(NodeFieldReference value) { int count = _data.Count; NodeFieldReference[] items = _data.Items; if ((object) value == null) { for (int i = 0; i < count; i++) { if ((object) items[i] == null) return i; } return -1; } for (int i = 0; i < count; i++) { if (value.Equals(items[i])) return i; } return -1; }
/// <summary> /// Adds the elements of a <see cref="NodeFieldReference"/> array /// to the end of the <see cref="NodeFieldReferenceCollection"/>. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="NodeFieldReference"/> /// elements that should be added to the end of the /// <see cref="NodeFieldReferenceCollection"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="NotSupportedException"><para> /// The <see cref="NodeFieldReferenceCollection"/> /// is read-only or has a fixed size. /// </para><para>-or-</para><para> /// The <b>NodeFieldReferenceCollection</b> already contains /// one or more elements in <paramref name="array"/>, /// and the <b>NodeFieldReferenceCollection</b> /// ensures that all elements are unique. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.AddRange"/> for details. /// </remarks> public virtual void AddRange(NodeFieldReference[] array) { if (array == null) throw new ArgumentNullException("array"); AddRange(array, array.Length); }
/// <overloads> /// Uses a binary search algorithm to locate a specific element /// in the sorted <see cref="NodeFieldReferenceCollection"/> /// or a portion of it. /// </overloads> /// <summary> /// Searches the entire sorted <see cref="NodeFieldReferenceCollection"/> /// for an <see cref="NodeFieldReference"/> element using the /// specified comparer and returns the zero-based index of the element. /// </summary> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to locate /// in the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <param name="comparer"> /// <para>The <see cref="IComparer"/> implementation /// to use when comparing elements.</para> /// <para>-or-</para> /// <para>A null reference to use the <see cref="IComparable"/> /// implementation of each element.</para></param> /// <returns> /// The zero-based index of <paramref name="value"/> in the sorted /// <see cref="NodeFieldReferenceCollection"/>, if <paramref name="value"/> /// is found; otherwise, a negative number, which is the bitwise /// complement of the index of the next element that is larger than /// <paramref name="value"/> or, if there is no larger element, the /// bitwise complement of <see cref="Count"/>.</returns> /// <exception cref="ArgumentException"> /// <paramref name="comparer"/> is a null reference, /// and NodeFieldReference does not implement /// the <see cref="IComparable"/> interface.</exception> /// <remarks> /// Please refer to /// <see cref="ArrayList.BinarySearch(Object, IComparer)"/> /// for details. /// </remarks> public int BinarySearch(NodeFieldReference value, IComparer comparer) { return Array.BinarySearch(_data.Items, 0, _data.Count, value, comparer); }
private void CheckUnique(NodeFieldReference value, int index) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException("Unique collections cannot contain duplicate elements."); }
/// <summary> /// Determines whether the <see cref="NodeFieldReferenceCollection"/> /// contains the specified <see cref="NodeFieldReference"/> element. /// </summary> /// <param name="value"> /// The <see cref="NodeFieldReference"/> object to locate /// in the <see cref="NodeFieldReferenceCollection"/>. /// This argument may be a null reference. /// </param> /// <returns> /// <c>true</c> if <paramref name="value"/> is found in the /// <see cref="NodeFieldReferenceCollection"/>; otherwise, <c>false</c>. /// </returns> /// <remarks> /// Please refer to <see cref="ArrayList.Contains"/> for details. /// </remarks> public bool Contains(NodeFieldReference value) { return (IndexOf(value) >= 0); }
public void SetCapacity(int capacity) { if (capacity == Items.Length) return; if (capacity == 0) { Items = new NodeFieldReference[DefaultCapacity]; return; } NodeFieldReference[] items = new NodeFieldReference[capacity]; Array.Copy(Items, items, Count); Items = items; }
/// <summary> /// Copies the entire <see cref="NodeFieldReferenceCollection"/> /// to a one-dimensional <see cref="Array"/> /// of <see cref="NodeFieldReference"/> elements, /// starting at the specified index of the target array. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array"/> that is the destination /// of the <see cref="NodeFieldReference"/> elements copied from the /// <see cref="NodeFieldReferenceCollection"/>. /// The <b>Array</b> must have zero-based indexing.</param> /// <param name="arrayIndex"> /// The zero-based index in <paramref name="array"/> /// at which copying begins.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="arrayIndex"/> is less than zero.</exception> /// <exception cref="ArgumentException"><para> /// <paramref name="arrayIndex"/> is equal to or /// greater than the length of <paramref name="array"/>. /// </para><para>-or-</para><para> /// The number of elements in the source /// <see cref="NodeFieldReferenceCollection"/> is greater /// than the available space from <paramref name="arrayIndex"/> /// to the end of the destination <paramref name="array"/>. /// </para></exception> /// <remarks> /// Please refer to <see cref="ArrayList.CopyTo"/> for details. /// </remarks> public void CopyTo(NodeFieldReference[] array, int arrayIndex) { ((ICollection) this).CopyTo(array, arrayIndex); }
public override int Add(NodeFieldReference value) { throw new NotSupportedException("Read-only collections cannot be modified."); }
private static void AddField(ISchemaEditorNode node, FieldInfo field, ISchemaEditorNodeFactory factory) { object fieldValue = field.GetValue(node.Value); NodeFieldReference fieldReference = new NodeFieldReference(node.Value, field, factory, node); node.AddNodeField(fieldReference); if (ReflectionUtil.HasValue(fieldValue) ) AddActiveChildNode(node,fieldReference, fieldValue, factory); }
public override void AddRange(NodeFieldReference[] array) { throw new NotSupportedException("Read-only collections cannot be modified."); }
public ElementSchemaError(NodeFieldReference field, ISchemaEditorNode parentNode) { this.field = field; this.parentNode = parentNode; }
public override void Insert(int index, NodeFieldReference value) { throw new NotSupportedException("Read-only collections cannot be modified."); }
/// <summary> /// Initializes a new instance of the /// <see cref="NodeFieldReferenceCollection"/> class /// that contains elements copied from the specified /// <see cref="NodeFieldReference"/> array and that has the /// same initial capacity as the number of elements copied. /// </summary> /// <param name="array"> /// An <see cref="Array"/> of <see cref="NodeFieldReference"/> /// elements that are copied to the new collection.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="array"/> is a null reference.</exception> /// <remarks> /// Please refer to <see cref="ArrayList(ICollection)"/> for details. /// </remarks> public NodeFieldReferenceCollection(NodeFieldReference[] array) { if (array == null) throw new ArgumentNullException("array"); _data = new Data(); _data.Items = new NodeFieldReference[array.Length]; AddRange(array, array.Length); }
// You can add if the field is an array, // or if it doesn't already have a value private bool CanAdd(NodeFieldReference field) { return field is ArrayNodeFieldReference || field.HasValue == false; }