readonly record struct CommitLink(

This commit is contained in:
M-L-Ml 2025-04-21 20:50:23 +02:00
parent 46ae4064f9
commit f381c1cfdb
3 changed files with 78 additions and 84 deletions

View file

@ -8,17 +8,9 @@ namespace SourceGit.Models
/// <summary>
/// Represents a commit link for a remote repository.
/// </summary>
public class CommitLink
public readonly record struct CommitLink(string Name, string URLPrefix)
{
public string Name { get; set; }
public string URLPrefix { get; set; }
public CommitLink(string name, string prefix)
{
Name = name;
URLPrefix = prefix;
}
public readonly record struct ProviderInfo(
string Name,
string HostPrefix,
@ -27,8 +19,9 @@ namespace SourceGit.Models
{
public bool IsMatch(string url) => url.StartsWith(HostPrefix, StringComparison.Ordinal);
}
private static readonly ProviderInfo[] Providers = new[]
public static class CommitLinkDetails // Changed from private to internal to fix CS1527
{
static readonly ProviderInfo[] Providers = new[]
{
new ProviderInfo(
"Github",
@ -97,7 +90,7 @@ namespace SourceGit.Models
/// </summary>
public static List<CommitLink> Get(List<Remote> remotes)
{
return remotes.Select(remote =>
return remotes.Select(static remote =>
{
var rr = TryCreateCommitLink(remote);
@ -111,7 +104,8 @@ namespace SourceGit.Models
}
#endif
return rr;
}).Where(cl => cl != null).ToList();
}).Select(cl => cl.Value) // Convert nullable CommitLink to non-nullable CommitLink
.Where(cl => cl != null).ToList();
}
#if DEBUG
@ -144,7 +138,7 @@ namespace SourceGit.Models
return outs.FirstOrDefault();
}
static CommitLink()
static CommitLinkDetails()
{
//Unit tests , TODO: make normal UnitTests, delete this code.

View file

@ -134,7 +134,7 @@ namespace SourceGit.ViewModels
public CommitDetail(Repository repo)
{
_repo = repo;
WebLinks = Models.CommitLink.Get(repo.Remotes);
WebLinks = Models.CommitLinkDetails.Get(repo.Remotes);
}
public void Cleanup()

View file

@ -37,7 +37,7 @@ namespace SourceGit.Views
get => GetValue(SupportsContainsInProperty);
set => SetValue(SupportsContainsInProperty, value);
}
//TODO: Maybe some observable container instead List? Add a comment for explanation.
public static readonly StyledProperty<List<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, List<Models.CommitLink>>(nameof(WebLinks));