| | | 1 | | // Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT |
| | | 2 | | using System.ComponentModel.DataAnnotations; |
| | | 3 | | |
| | | 4 | | namespace DotNetApiDiff.Models; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents a public API member from a .NET assembly |
| | | 8 | | /// </summary> |
| | | 9 | | public class ApiMember |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Simple name of the member |
| | | 13 | | /// </summary> |
| | | 14 | | [Required] |
| | 222 | 15 | | public string Name { get; set; } = string.Empty; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Full qualified name of the member |
| | | 19 | | /// </summary> |
| | | 20 | | [Required] |
| | 253 | 21 | | public string FullName { get; set; } = string.Empty; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Type of the member (Class, Method, Property, etc.) |
| | | 25 | | /// </summary> |
| | 76 | 26 | | public MemberType Type { get; set; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Accessibility level of the member |
| | | 30 | | /// </summary> |
| | 68 | 31 | | public AccessibilityLevel Accessibility { get; set; } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Normalized signature of the member for comparison |
| | | 35 | | /// </summary> |
| | | 36 | | [Required] |
| | 216 | 37 | | public string Signature { get; set; } = string.Empty; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// List of attributes applied to the member |
| | | 41 | | /// </summary> |
| | 137 | 42 | | public List<string> Attributes { get; set; } = new List<string>(); |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Name of the type that declares this member |
| | | 46 | | /// </summary> |
| | 120 | 47 | | public string DeclaringType { get; set; } = string.Empty; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Namespace containing this member |
| | | 51 | | /// </summary> |
| | 124 | 52 | | public string Namespace { get; set; } = string.Empty; |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Validates the ApiMember instance |
| | | 56 | | /// </summary> |
| | | 57 | | /// <returns>True if valid, false otherwise</returns> |
| | | 58 | | public bool IsValid() |
| | 7 | 59 | | { |
| | 7 | 60 | | return !string.IsNullOrWhiteSpace(Name) && |
| | 7 | 61 | | !string.IsNullOrWhiteSpace(FullName) && |
| | 7 | 62 | | !string.IsNullOrWhiteSpace(Signature); |
| | 7 | 63 | | } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets a string representation of the member |
| | | 67 | | /// </summary> |
| | | 68 | | public override string ToString() |
| | 1 | 69 | | { |
| | 1 | 70 | | return $"{Type} {FullName} ({Accessibility})"; |
| | 1 | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Determines equality based on FullName and Signature |
| | | 75 | | /// </summary> |
| | | 76 | | public override bool Equals(object? obj) |
| | 5 | 77 | | { |
| | 5 | 78 | | if (obj is not ApiMember other) |
| | 2 | 79 | | { |
| | 2 | 80 | | return false; |
| | | 81 | | } |
| | | 82 | | |
| | 3 | 83 | | return FullName == other.FullName && Signature == other.Signature; |
| | 5 | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Gets hash code based on FullName and Signature |
| | | 88 | | /// </summary> |
| | | 89 | | public override int GetHashCode() |
| | 2 | 90 | | { |
| | 2 | 91 | | return HashCode.Combine(FullName, Signature); |
| | 2 | 92 | | } |
| | | 93 | | } |