| | 1 | | // Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT |
| | 2 | | namespace DotNetApiDiff.Models; |
| | 3 | |
|
| | 4 | | /// <summary> |
| | 5 | | /// Represents the complete comparison result between two API surfaces |
| | 6 | | /// </summary> |
| | 7 | | public class ApiComparison |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// List of API members that were added |
| | 11 | | /// </summary> |
| 92 | 12 | | public List<ApiChange> Additions { get; set; } = new List<ApiChange>(); |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// List of API members that were removed |
| | 16 | | /// </summary> |
| 89 | 17 | | public List<ApiChange> Removals { get; set; } = new List<ApiChange>(); |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// List of API members that were modified |
| | 21 | | /// </summary> |
| 83 | 22 | | public List<ApiChange> Modifications { get; set; } = new List<ApiChange>(); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// List of API members that were intentionally excluded |
| | 26 | | /// </summary> |
| 75 | 27 | | public List<ApiChange> Excluded { get; set; } = new List<ApiChange>(); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Summary statistics of the comparison |
| | 31 | | /// </summary> |
| 47 | 32 | | public ComparisonSummary Summary { get; set; } = new ComparisonSummary(); |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Gets all changes as a single collection |
| | 36 | | /// </summary> |
| | 37 | | public IEnumerable<ApiChange> AllChanges |
| | 38 | | { |
| | 39 | | get |
| 32 | 40 | | { |
| 32 | 41 | | return Additions.Concat(Removals).Concat(Modifications).Concat(Excluded); |
| 32 | 42 | | } |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Gets whether any breaking changes were detected |
| | 47 | | /// </summary> |
| 18 | 48 | | public bool HasBreakingChanges => AllChanges.Any(c => c.IsBreakingChange); |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Gets the total number of changes (excluding excluded items) |
| | 52 | | /// </summary> |
| 3 | 53 | | public int TotalChanges => Additions.Count + Removals.Count + Modifications.Count; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets the total number of breaking changes |
| | 57 | | /// </summary> |
| 23 | 58 | | public int BreakingChangesCount => AllChanges.Count(c => c.IsBreakingChange); |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Validates the ApiComparison instance |
| | 62 | | /// </summary> |
| | 63 | | /// <returns>True if valid, false otherwise</returns> |
| | 64 | | public bool IsValid() |
| 12 | 65 | | { |
| | 66 | | // Validate all changes |
| 12 | 67 | | var allChanges = AllChanges.ToList(); |
| 25 | 68 | | if (allChanges.Any(c => !c.IsValid())) |
| 5 | 69 | | { |
| 5 | 70 | | return false; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | // Validate that additions only contain Added changes |
| 10 | 74 | | if (Additions.Any(c => c.Type != ChangeType.Added)) |
| 0 | 75 | | { |
| 0 | 76 | | return false; |
| | 77 | | } |
| | 78 | |
|
| | 79 | | // Validate that removals only contain Removed changes |
| 11 | 80 | | if (Removals.Any(c => c.Type != ChangeType.Removed)) |
| 0 | 81 | | { |
| 0 | 82 | | return false; |
| | 83 | | } |
| | 84 | |
|
| | 85 | | // Validate that modifications only contain Modified changes |
| 8 | 86 | | if (Modifications.Any(c => c.Type != ChangeType.Modified)) |
| 1 | 87 | | { |
| 1 | 88 | | return false; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | // Validate that excluded only contain Excluded changes |
| 6 | 92 | | if (Excluded.Any(c => c.Type != ChangeType.Excluded)) |
| 0 | 93 | | { |
| 0 | 94 | | return false; |
| | 95 | | } |
| | 96 | |
|
| 6 | 97 | | return true; |
| 12 | 98 | | } |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Updates the summary statistics based on current changes |
| | 102 | | /// </summary> |
| | 103 | | public void UpdateSummary() |
| 2 | 104 | | { |
| 2 | 105 | | Summary.AddedCount = Additions.Count; |
| 2 | 106 | | Summary.RemovedCount = Removals.Count; |
| 2 | 107 | | Summary.ModifiedCount = Modifications.Count; |
| 2 | 108 | | Summary.BreakingChangesCount = BreakingChangesCount; |
| 2 | 109 | | } |
| | 110 | | } |