Skip to content

Commit

Permalink
#44 Disposable Instances Handling - fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 20, 2024
1 parent 5eafcb4 commit f35338d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
12 changes: 6 additions & 6 deletions build/CompatibilityCheckTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public async Task<IReadOnlyCollection<Package>> RunAsync(CancellationToken cance
"netcoreapp2.0",
"netcoreapp1.1",
"netcoreapp1.0",
"net48",
"net45",
"net35",
"net20",
"netstandard1.3",
"netstandard1.4",
"netstandard1.5",
"netstandard1.6",
"netstandard2.0",
"netstandard2.1"
"netstandard2.1",
"net48",
"net45",
"net35",
"net20"
];

foreach (var framework in frameworks)
foreach (var framework in frameworks.Reverse())
{
await CompatibilityCheckAsync(generatorPackage.Path, framework, cancellationToken);
}
Expand Down
34 changes: 13 additions & 21 deletions src/Pure.DI.Core/Components/Api.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ internal enum Tag
/// <summary>
/// Gives the opportunity to collect disposable objects.
/// </summary>
public class Owned : global::System.IDisposable
public partial class Owned : global::System.IDisposable
{
private bool _isDisposed;
private global::System.Collections.Generic.List<global::System.IDisposable> _disposables
= new global::System.Collections.Generic.List<global::System.IDisposable>();

Expand All @@ -1117,39 +1116,32 @@ public void Dispose()
global::System.Collections.Generic.List<global::System.IDisposable> disposables;
lock (_disposables)
{
if (_isDisposed)
{
return;
}

_isDisposed = true;
disposables = _disposables;
_disposables = new global::System.Collections.Generic.List<global::System.IDisposable>();
}

disposables.Reverse();
global::System.Collections.Generic.List<global::System.Exception> errors = null;
foreach (var disposable in disposables)
{
try
{
disposable.Dispose();
}
catch (global::System.Exception error)
catch (global::System.Exception exception)
{
if (errors == null)
{
errors = new global::System.Collections.Generic.List<global::System.Exception>();
}

errors.Add(error);
OnDisposeException(disposable, exception);
}
}

if (errors != null)
{
throw new global::System.AggregateException(errors);
}
}

/// <summary>
/// Implement this partial method to handle the exception on disposing.
/// </summary>
/// <param name="disposableInstance">The disposable instance.</param>
/// <param name="exception">Exception occurring during disposal.</param>
/// <typeparam name="T">The actual type of instance being disposed of.</typeparam>
partial void OnDisposeException<T>(T disposableInstance, Exception exception)
where T : global::System.IDisposable;
}

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/Pure.DI.Core/Core/Code/DisposeMethodBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// ReSharper disable ClassNeverInstantiated.Global
namespace Pure.DI.Core.Code;

internal sealed class DisposeMethodBuilder: IBuilder<CompositionCode, CompositionCode>
internal sealed class DisposeMethodBuilder()
: IBuilder<CompositionCode, CompositionCode>
{
public CompositionCode Build(CompositionCode composition)
{
Expand Down Expand Up @@ -76,6 +77,12 @@ public CompositionCode Build(CompositionCode composition)
membersCounter++;

code.AppendLine();
code.AppendLine("/// <summary>");
code.AppendLine("/// Implement this partial method to handle the exception on disposing.");
code.AppendLine("/// <summary>");
code.AppendLine("/// <param name=\"disposableInstance\">The disposable instance.</param>");
code.AppendLine("/// <param name=\"exception\">Exception occurring during disposal.</param>");
code.AppendLine("/// <typeparam name=\"T\">The actual type of instance being disposed of.</typeparam>");
code.AppendLine($"partial void {Names.OnDisposeExceptionMethodName}<T>(T disposableInstance, Exception exception) where T : {Names.IDisposableInterfaceName};");
code.AppendLine();
membersCounter++;
Expand Down

0 comments on commit f35338d

Please sign in to comment.