Esempio n. 1
0
        /// <summary>
        /// To be merged with another type definition, <see cref="Kind"/> and <see cref="TypeName.Key"/> must be the same
        /// otherwise an <see cref="InvalidOperationException"/> is thrown.
        /// </summary>
        /// <param name="other">The other type definition.</param>
        /// <returns>The merged definition.</returns>
        public void MergeWith(TypeDefinition other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            if (Kind != other.Kind)
            {
                throw new InvalidOperationException($"Unable to merge type '{ToString()}' with '{other}': Kind differ {Kind} vs. {other.Kind}.");
            }
            if (Name.Key != other.Name.Key)
            {
                throw new InvalidOperationException($"Unable to merge type '{ToString()}' with '{other}': TypeDefinitionKey differ {Name.Key} vs. {other.Name.Key}.");
            }

            Attributes.MergeWith(other.Attributes);
            Modifiers |= other.Modifiers;

            var baseTypes = new HashSet <ExtendedTypeName>(BaseTypes.Concat(other.BaseTypes));

            BaseTypes.Clear();
            BaseTypes.AddRange(baseTypes);

            var constraints = new HashSet <TypeParameterConstraint>(Constraints.Concat(other.Constraints));

            Constraints.Clear();
            Constraints.AddRange(constraints);
        }