예제 #1
0
        /// <summary>
        /// Merges this annotation with the given annotation and returns a new annotation containing the merged indexes.
        /// </summary>
        /// <remarks>
        /// Each index annotation contains at most one <see cref="T:System.ComponentModel.DataAnnotations.Schema.IndexAttribute" /> with a given name.
        /// The merged annotation will contain IndexAttributes from both this and the other annotation.
        /// If both annotations contain an IndexAttribute with the same name, then the merged annotation
        /// will contain one IndexAttribute with that name.
        /// </remarks>
        /// <param name="other">The annotation to merge with this one.</param>
        /// <returns>A new annotation with indexes from both annotations merged.</returns>
        /// <exception cref="T:System.InvalidOperationException">
        /// The other annotation contains indexes that are not compatible with indexes in this annotation.
        /// </exception>
        public virtual object MergeWith(object other)
        {
            if (object.ReferenceEquals((object)this, other) || other == null)
            {
                return((object)this);
            }
            IndexAnnotation indexAnnotation = other as IndexAnnotation;

            if (indexAnnotation == null)
            {
                throw new ArgumentException(Strings.IncompatibleTypes((object)other.GetType().Name, (object)typeof(IndexAnnotation).Name));
            }
            List <IndexAttribute> list = this._indexes.ToList <IndexAttribute>();

            IndexAnnotation.MergeLists((ICollection <IndexAttribute>)list, (IEnumerable <IndexAttribute>)indexAnnotation._indexes, (PropertyInfo)null);
            return((object)new IndexAnnotation((IEnumerable <IndexAttribute>)list));
        }
예제 #2
0
 internal IndexAnnotation(PropertyInfo propertyInfo, IEnumerable <IndexAttribute> indexAttributes)
 {
     Check.NotNull <IEnumerable <IndexAttribute> >(indexAttributes, nameof(indexAttributes));
     IndexAnnotation.MergeLists((ICollection <IndexAttribute>) this._indexes, indexAttributes, propertyInfo);
 }
예제 #3
0
 /// <summary>
 /// Creates a new annotation for the given collection of indexes.
 /// </summary>
 /// <param name="indexAttributes">Index attributes representing one or more indexes.</param>
 public IndexAnnotation(IEnumerable <IndexAttribute> indexAttributes)
 {
     Check.NotNull <IEnumerable <IndexAttribute> >(indexAttributes, nameof(indexAttributes));
     IndexAnnotation.MergeLists((ICollection <IndexAttribute>) this._indexes, indexAttributes, (PropertyInfo)null);
 }