public static TypeDescription Merge(TypeDescription previousDescription, TypeDescription currentDescription, TypeDescription baseTypeDescription) { previousDescription.ThrowOnBreakingChanges(currentDescription); var type = previousDescription.ResolvedType; var typename = currentDescription.FullTypeName; var typeId = currentDescription.TypeId; var classification = currentDescription.Classification; var underlying = currentDescription.UnderlyingEnumTypeDescription; var fields = FieldDescription.Merge(previousDescription.Fields, currentDescription.Fields); var description = new TypeDescription(type, typename, typeId, baseTypeDescription, underlying, classification, fields); return(description); }
private void ThrowOnBreakingChanges(TypeDescription otherDescription) { if (Classification != otherDescription.Classification) { throw new BreakingChangeException(); } foreach (var field in _fields) { var otherField = otherDescription._fields.FirstOrDefault(x => Equals(x.Name, field.Name)); if (otherField != null) { field.ThrowOnBreakingChanges(otherField); } } var otherUnderlyingType = otherDescription.UnderlyingEnumTypeDescription; if (UnderlyingEnumTypeDescription == null && otherUnderlyingType != null) { throw new BreakingChangeException(); } if (UnderlyingEnumTypeDescription != null && otherUnderlyingType == null) { throw new BreakingChangeException(); } if (UnderlyingEnumTypeDescription != null && otherUnderlyingType != null) { if (!AreSameType(UnderlyingEnumTypeDescription, otherUnderlyingType)) { throw new BreakingChangeException(); } } var otherBaseType = otherDescription.BaseType; if (BaseType == null && otherBaseType != null) { throw new BreakingChangeException(string.Format("The base class of the type '{0}' has been changed from 'null' to '{1}': This is a breaking change!", FullTypeName, otherBaseType.FullTypeName)); } if (BaseType != null && otherBaseType == null) { throw new BreakingChangeException(string.Format("The base class of the type '{0}' has been changed from '{1}' to '{0}': This is a breaking change!", FullTypeName, BaseType.FullTypeName)); } if (BaseType != null && otherBaseType != null) { if (!AreSameType(BaseType, otherBaseType)) { throw new BreakingChangeException(string.Format("The base class of the type '{0}' has been changed from '{1}' to '{2}': This is a breaking change!", FullTypeName, BaseType.FullTypeName, otherBaseType.FullTypeName)); } BaseType.ThrowOnBreakingChanges(otherDescription.BaseType); } }