diff --git a/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs b/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs index b98a7586..657f4107 100644 --- a/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs @@ -50,7 +50,7 @@ public CompositionCode Build(DependencyGraph graph) ctx.Code.AppendLine($"return {buildTools.OnInjected(ctx, rootBlock.Current)};"); ctx.Code.AppendLines(ctx.LocalFunctionsCode.Lines); - var args = GetRootArgs(map.Values).ToImmutableArray(); + var args = GetRootArgs(map.Values).ToList(); var processedRoot = root with { Lines = ctx.Code.Lines.ToImmutableArray(), diff --git a/src/Pure.DI.Core/Core/Code/IInjections.cs b/src/Pure.DI.Core/Core/Code/IInjections.cs index 6ab28a7a..8bb7313a 100644 --- a/src/Pure.DI.Core/Core/Code/IInjections.cs +++ b/src/Pure.DI.Core/Core/Code/IInjections.cs @@ -6,5 +6,5 @@ internal interface IInjections void PropertyInjection(string targetName, BuildContext ctx, DpProperty property, Variable propertyVariable); - void MethodInjection(string targetName, BuildContext ctx, DpMethod method, ImmutableArray methodArgs); + void MethodInjection(string targetName, BuildContext ctx, DpMethod method, IReadOnlyList methodArgs); } \ No newline at end of file diff --git a/src/Pure.DI.Core/Core/Code/ImplementationCodeBuilder.cs b/src/Pure.DI.Core/Core/Code/ImplementationCodeBuilder.cs index b86f1215..89746782 100644 --- a/src/Pure.DI.Core/Core/Code/ImplementationCodeBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ImplementationCodeBuilder.cs @@ -109,9 +109,9 @@ public void Build(BuildContext ctx, in DpImplementation implementation) private string CreateInstantiation( BuildContext ctx, - ImmutableArray constructorArgs, - ImmutableArray<(Variable RequiredVariable, DpField RequiredField)>.Builder requiredFields, - ImmutableArray<(Variable RequiredVariable, DpProperty RequiredProperty)>.Builder requiredProperties) + IReadOnlyCollection constructorArgs, + IReadOnlyCollection<(Variable RequiredVariable, DpField RequiredField)> requiredFields, + IReadOnlyCollection<(Variable RequiredVariable, DpProperty RequiredProperty)> requiredProperties) { var code = new StringBuilder(); var variable = ctx.Variable; diff --git a/src/Pure.DI.Core/Core/Code/Injections.cs b/src/Pure.DI.Core/Core/Code/Injections.cs index c15942d2..01eb3790 100644 --- a/src/Pure.DI.Core/Core/Code/Injections.cs +++ b/src/Pure.DI.Core/Core/Code/Injections.cs @@ -12,10 +12,10 @@ public void PropertyInjection(string targetName, BuildContext ctx, DpProperty p ctx.Code.AppendLine($"{targetName}.{property.Property.Name} = {ctx.BuildTools.OnInjected(ctx, propertyVariable)};"); } - public void MethodInjection(string targetName, BuildContext ctx, DpMethod method, ImmutableArray methodArgs) + public void MethodInjection(string targetName, BuildContext ctx, DpMethod method, IReadOnlyList methodArgs) { var args = new List(); - for (var index = 0; index < methodArgs.Length; index++) + for (var index = 0; index < methodArgs.Count; index++) { var variable = methodArgs[index]; if (index < method.Parameters.Length) diff --git a/src/Pure.DI.Core/Core/Code/ResolverInfo.cs b/src/Pure.DI.Core/Core/Code/ResolverInfo.cs index 3f5f6640..e50aff4e 100644 --- a/src/Pure.DI.Core/Core/Code/ResolverInfo.cs +++ b/src/Pure.DI.Core/Core/Code/ResolverInfo.cs @@ -3,7 +3,7 @@ namespace Pure.DI.Core.Code; internal record ResolverInfo( int Id, ITypeSymbol Type, - ImmutableArray Roots) + IReadOnlyCollection Roots) { public string ClassName => $"{Names.ResolverClassName}_{Id:0000}"; } \ No newline at end of file diff --git a/src/Pure.DI.Core/Core/Code/ResolversBuilder.cs b/src/Pure.DI.Core/Core/Code/ResolversBuilder.cs index 5b1674a0..b9e13fc7 100644 --- a/src/Pure.DI.Core/Core/Code/ResolversBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ResolversBuilder.cs @@ -12,5 +12,5 @@ public IEnumerable Build(RootContext ctx) => .Where(i => !ReferenceEquals(i.Injection.Tag, MdTag.ContextTag)) .Where(i => typeResolver.Resolve(ctx.Setup, i.Injection.Type).TypeArgs.Count == 0) .GroupBy(i => i.Injection.Type, SymbolEqualityComparer.Default) - .Select((i, id) => new ResolverInfo(id, (ITypeSymbol)i.Key!, i.ToImmutableArray())); + .Select((i, id) => new ResolverInfo(id, (ITypeSymbol)i.Key!, i.ToList())); } \ No newline at end of file diff --git a/src/Pure.DI.Core/Core/Code/TypeResolver.cs b/src/Pure.DI.Core/Core/Code/TypeResolver.cs index 5370864e..b22c8b39 100644 --- a/src/Pure.DI.Core/Core/Code/TypeResolver.cs +++ b/src/Pure.DI.Core/Core/Code/TypeResolver.cs @@ -45,7 +45,7 @@ private TypeDescription Resolve(MdSetup setup, ITypeSymbol type, ITypeParameterS args.AddRange(item.description.TypeArgs); } - description = new TypeDescription($"({string.Join(", ", elements)})", args.Distinct().ToImmutableArray(), typeParam); + description = new TypeDescription($"({string.Join(", ", elements)})", args.Distinct().ToList(), typeParam); } break; @@ -60,7 +60,7 @@ private TypeDescription Resolve(MdSetup setup, ITypeSymbol type, ITypeParameterS } var name = string.Join("", namedTypeSymbol.ToDisplayParts().TakeWhile(i => i.ToString() != "<")); - description = new TypeDescription($"{name}<{string.Join(", ", types)}>", args.Distinct().ToImmutableArray(), typeParam); + description = new TypeDescription($"{name}<{string.Join(", ", types)}>", args.Distinct().ToList(), typeParam); } break; diff --git a/src/Pure.DI.Core/Core/DependenciesToVariablesWalker.cs b/src/Pure.DI.Core/Core/DependenciesToVariablesWalker.cs index dcb51b82..69dbc842 100644 --- a/src/Pure.DI.Core/Core/DependenciesToVariablesWalker.cs +++ b/src/Pure.DI.Core/Core/DependenciesToVariablesWalker.cs @@ -14,9 +14,9 @@ public DependenciesToVariablesWalker(ICollection variables) .ToDictionary(i => i.Key, i => new LinkedList(i)); } - public ImmutableArray GetResult() + public IReadOnlyList GetResult() { - var result = _resultBuilder.ToImmutable(); + var result = _resultBuilder.ToList(); _resultBuilder.Clear(); return result; } diff --git a/src/Pure.DI.Core/Core/DependencyGraphBuilder.cs b/src/Pure.DI.Core/Core/DependencyGraphBuilder.cs index ec236ff7..99575deb 100644 --- a/src/Pure.DI.Core/Core/DependencyGraphBuilder.cs +++ b/src/Pure.DI.Core/Core/DependencyGraphBuilder.cs @@ -6,7 +6,7 @@ namespace Pure.DI.Core; -using Injection = Models.Injection; +using Injection = Injection; internal sealed class DependencyGraphBuilder( IEnumerable>> dependencyNodeBuilders, @@ -341,7 +341,7 @@ public IEnumerable TryBuild( edges.Add(dependency); } - entries.Add(new GraphEntry(node.Node, edges.ToImmutableArray())); + entries.Add(new GraphEntry(node.Node, edges)); } var graph = new Graph(entries); diff --git a/src/Pure.DI.Core/Core/DependencyGraphLocationsWalker.cs b/src/Pure.DI.Core/Core/DependencyGraphLocationsWalker.cs index 190be8c1..5e789eea 100644 --- a/src/Pure.DI.Core/Core/DependencyGraphLocationsWalker.cs +++ b/src/Pure.DI.Core/Core/DependencyGraphLocationsWalker.cs @@ -6,7 +6,7 @@ internal sealed class DependencyGraphLocationsWalker(in Injection injection) private readonly Injection _injection = injection; private readonly ImmutableArray.Builder _locationsBuilder = ImmutableArray.CreateBuilder(); - public ImmutableArray Locations => _locationsBuilder.ToImmutableArray(); + public IReadOnlyCollection Locations => _locationsBuilder.ToList(); public override void VisitInjection( in Unit ctx, diff --git a/src/Pure.DI.Core/Core/Disposables.cs b/src/Pure.DI.Core/Core/Disposables.cs index 8051b0e3..bb902f91 100644 --- a/src/Pure.DI.Core/Core/Disposables.cs +++ b/src/Pure.DI.Core/Core/Disposables.cs @@ -16,9 +16,9 @@ internal static class Disposables public static IDisposable Create(Action action) => new DisposableAction(action); public static IDisposable Create(params IDisposable[] disposables) => - Create(disposables.ToImmutableArray()); + Create(disposables.ToList()); - public static IDisposable Create(in ImmutableArray disposables) => + public static IDisposable Create(in IReadOnlyCollection disposables) => new CompositeDisposable(disposables); public static IDisposable Create(IEnumerable disposables) => @@ -64,9 +64,9 @@ public override int GetHashCode() => _key != null ? _key.GetHashCode() : 0; } - private class CompositeDisposable(in ImmutableArray disposables) : IDisposable + private class CompositeDisposable(in IReadOnlyCollection disposables) : IDisposable { - private readonly ImmutableArray _disposables = disposables; + private readonly IReadOnlyCollection _disposables = disposables; private int _counter; public void Dispose() diff --git a/src/Pure.DI.Core/Core/Graph.cs b/src/Pure.DI.Core/Core/Graph.cs index 97a21c89..c7ef87bc 100644 --- a/src/Pure.DI.Core/Core/Graph.cs +++ b/src/Pure.DI.Core/Core/Graph.cs @@ -6,7 +6,6 @@ internal sealed class Graph : IGraph where TEdge : IEdge where TVertex : notnull { - private readonly List> _entries = []; private readonly Dictionary> _inOutEdges; private readonly Dictionary> _outInEdges; private readonly List _edges = []; @@ -20,7 +19,6 @@ public Graph( var outInEdges = new Dictionary>(comparer); foreach (var entry in entries) { - _entries.Add(entry); _inOutEdges.Add(entry.Target, entry); foreach (var edge in entry.Edges) { @@ -35,7 +33,9 @@ public Graph( } } - _outInEdges = outInEdges.ToDictionary(i => i.Key, i => new GraphEntry(i.Key, i.Value)); + _outInEdges = outInEdges.ToDictionary( + i => i.Key, + i => new GraphEntry(i.Key, i.Value)); } public IEnumerable Vertices => _inOutEdges.Keys; @@ -65,10 +65,4 @@ public bool TryGetOutEdges(in TVertex source, out IReadOnlyCollection edg edges = ImmutableArray.Empty; return false; } - - public IGraph Consolidate(ISet vertices) => - new Graph( - _entries.Where(i => - vertices.Contains(i.Target) - || vertices.Intersect(i.Edges.Select(j => j.Source)).Any())); } \ No newline at end of file diff --git a/src/Pure.DI.Core/Core/InitializersWalker.cs b/src/Pure.DI.Core/Core/InitializersWalker.cs index 55d88e06..c1f1a771 100644 --- a/src/Pure.DI.Core/Core/InitializersWalker.cs +++ b/src/Pure.DI.Core/Core/InitializersWalker.cs @@ -33,7 +33,7 @@ public override void VisitMethod(in BuildContext ctx, in DpMethod method) base.VisitMethod(in ctx, in method); var curCtx = ctx; var curMethod = method; - var curVariables = _variables.ToImmutableArray(); + var curVariables = _variables.ToList(); _actions.Add(new (() => injections.MethodInjection(variableName, curCtx, curMethod, curVariables), curMethod.Ordinal)); _variables.Clear(); } diff --git a/src/Pure.DI.Core/Core/InstanceDpProvider.cs b/src/Pure.DI.Core/Core/InstanceDpProvider.cs index 151e5209..f1fd7a41 100644 --- a/src/Pure.DI.Core/Core/InstanceDpProvider.cs +++ b/src/Pure.DI.Core/Core/InstanceDpProvider.cs @@ -20,7 +20,6 @@ public InstanceDp Get( setupAttributesBuilder.AddRange(setup.TagAttributes); setupAttributesBuilder.AddRange(setup.TypeAttributes); var setupAttributes = setupAttributesBuilder.MoveToImmutable(); - var methods = new List(); var fields = new List(); var properties = new List(); diff --git a/tests/Pure.DI.IntegrationTests/TestExtensions.cs b/tests/Pure.DI.IntegrationTests/TestExtensions.cs index 13e7d9f0..d73ab822 100644 --- a/tests/Pure.DI.IntegrationTests/TestExtensions.cs +++ b/tests/Pure.DI.IntegrationTests/TestExtensions.cs @@ -85,7 +85,7 @@ internal static async Task RunAsync(this string setupCode, Options? opti logs, errors, warnings, - dependencyGraphObserver.Values.ToImmutableArray(), + dependencyGraphObserver.Values, string.Empty); } @@ -129,7 +129,7 @@ internal static async Task RunAsync(this string setupCode, Options? opti logs, errors, warnings, - dependencyGraphObserver.Values.ToImmutableArray(), + dependencyGraphObserver.Values, generatedCode); } @@ -166,7 +166,7 @@ internal static async Task RunAsync(this string setupCode, Options? opti logs, errors, warnings, - dependencyGraphObserver.Values.ToImmutableArray(), + dependencyGraphObserver.Values, generatedCode); void StdOutReceived(object sender, DataReceivedEventArgs args) diff --git a/tests/Pure.DI.IntegrationTests/TuplesTests.cs b/tests/Pure.DI.IntegrationTests/TuplesTests.cs index b3cc58ba..f78bc6b7 100644 --- a/tests/Pure.DI.IntegrationTests/TuplesTests.cs +++ b/tests/Pure.DI.IntegrationTests/TuplesTests.cs @@ -125,8 +125,8 @@ public static void Main() // Then result.Success.ShouldBeFalse(result); - var errors = result.Logs.Where(i => i.Id == LogId.ErrorUnableToResolve).ToImmutableArray(); - errors.Length.ShouldBe(1, result); + var errors = result.Logs.Where(i => i.Id == LogId.ErrorUnableToResolve).ToList(); + errors.Count.ShouldBe(1, result); } [Fact] diff --git a/tests/Pure.DI.UsageTests/Hints/OnNewInstanceHintScenario.cs b/tests/Pure.DI.UsageTests/Hints/OnNewInstanceHintScenario.cs index 9e8f0700..0889472d 100644 --- a/tests/Pure.DI.UsageTests/Hints/OnNewInstanceHintScenario.cs +++ b/tests/Pure.DI.UsageTests/Hints/OnNewInstanceHintScenario.cs @@ -18,7 +18,6 @@ namespace Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario; -using System.Collections.Immutable; using Shouldly; using Xunit;