Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1c68028

Browse files
committed
Add Defer
1 parent fd9fd3d commit 1c68028

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ServiceStack.Text/Defer.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace ServiceStack
4+
{
5+
/// <summary>
6+
/// Useful class for C# 8 using declaration to defer action til outside of scope, e.g:
7+
/// using var defer = new Defer(() => response.Close());
8+
/// </summary>
9+
public struct Defer : IDisposable
10+
{
11+
private readonly Action fn;
12+
public Defer(Action fn) => this.fn = fn ?? throw new ArgumentNullException(nameof(fn));
13+
public void Dispose() => fn();
14+
}
15+
}

tests/ServiceStack.Text.Tests/RuntimeSerializtionTests.cs renamed to tests/ServiceStack.Text.Tests/RuntimeSerializationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class RuntimeObjects
5757
public object[] Objects { get; set; }
5858
}
5959

60-
public class RuntimeSerializtionTests
60+
public class RuntimeSerializationTests
6161
{
6262
string CreateJson(Type type) => CreateJson(type.AssemblyQualifiedName);
6363
string CreateJson(string typeInfo) => "{\"Object\":{\"__type\":\"" + typeInfo + "\"}}";

0 commit comments

Comments
 (0)