Skip to content

Commit 8e4c2ff

Browse files
committed
Use expression bodies
1 parent a0b1f92 commit 8e4c2ff

File tree

57 files changed

+172
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+172
-378
lines changed

src/AdditionalPatterns/EventAggregator/StoreManagement/Components/EventAggregator.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,16 @@ public void Publish(IEvent @event)
4646
/// </summary>
4747
/// <param name="observer">The subscriber.</param>
4848
/// <returns>An unsubscriber to allow unsubscribing from events.</returns>
49-
public IDisposable Subscribe(IObserver<IEvent> observer)
50-
{
51-
return SubscribeToAllEvents(observer);
52-
}
49+
public IDisposable Subscribe(IObserver<IEvent> observer) =>
50+
SubscribeToAllEvents(observer);
5351

5452
/// <summary>
5553
/// Subscribe to all events.
5654
/// </summary>
5755
/// <param name="observer">The subscriber.</param>
5856
/// <returns>An unsubscriber to allow unsubscribing from events.</returns>
59-
public IDisposable Subscribe(ICustomObserver<IEvent> observer)
60-
{
61-
return SubscribeToAllEvents(observer);
62-
}
57+
public IDisposable Subscribe(ICustomObserver<IEvent> observer) =>
58+
SubscribeToAllEvents(observer);
6359

6460
/// <summary>
6561
/// Subscribe to a specific event type.
@@ -78,10 +74,8 @@ public IDisposable Subscribe<T>(ICustomObserver<T> newObserver)
7874
return SubscribeAndSendEvents(observers, newObserver, _events.Where(evt => evt is T));
7975
}
8076

81-
private IDisposable SubscribeToAllEvents(IObserver<IEvent> newObserver)
82-
{
83-
return SubscribeAndSendEvents(_observers, newObserver, _events);
84-
}
77+
private IDisposable SubscribeToAllEvents(IObserver<IEvent> newObserver) =>
78+
SubscribeAndSendEvents(_observers, newObserver, _events);
8579

8680
private IDisposable SubscribeAndSendEvents(
8781
List<IObserver<IEvent>> currentObservers,

src/AdditionalPatterns/EventAggregator/StoreManagement/Components/Publishers/OrderPublisher.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public OrderPublisher(IEventAggregator eventAggregator)
1212
_eventAggregator = eventAggregator;
1313
}
1414

15-
public void Publish(string payload)
16-
{
15+
public void Publish(string payload) =>
1716
_eventAggregator.Publish(new OrderCreatedEvent(payload));
18-
}
19-
}
17+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Components/Publishers/WarehousePublisher.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public WarehousePublisher(IEventAggregator eventAggregator)
1212
_eventAggregator = eventAggregator;
1313
}
1414

15-
public void Publish(string payload)
16-
{
15+
public void Publish(string payload) =>
1716
_eventAggregator.Publish(new WarehouseReceivedNewSuppliesEvent(payload));
18-
}
19-
}
17+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Components/Subscribers/BusinessTrackingSubscriber.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,14 @@ public void OnNext(IEvent @event)
2222
Console.WriteLine($"{GetType().Name}: event record is available for various reports.");
2323
}
2424

25-
public void OnCompleted()
26-
{
25+
public void OnCompleted() =>
2726
Console.WriteLine($"{GetType().Name}: finished event processing.");
28-
}
2927

30-
public void OnError(Exception error)
31-
{
28+
public void OnError(Exception error) =>
3229
Console.WriteLine($"{GetType().Name}: experienced error condition.");
33-
}
3430

35-
public void Unsubscribe()
36-
{
31+
public void Unsubscribe() =>
3732
// If subscribe method needs to be called multiple times unsubscribe
3833
// mechanism must be changed in order to support such functionality.
3934
_unsubscriber.Dispose();
40-
}
41-
}
35+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Components/Subscribers/OrderSubscriber.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,15 @@ public OrderSubscriber(IEventAggregator eventAggregator)
1717
_unsubscriber = _eventAggregator.Subscribe(this);
1818
}
1919

20-
public void OnNext(IEvent @event)
21-
{
20+
public void OnNext(IEvent @event) =>
2221
Console.WriteLine($"{GetType().Name}: processing event with description '{@event.Description}'.");
23-
}
2422

25-
public void OnCompleted()
26-
{
23+
public void OnCompleted() =>
2724
Console.WriteLine($"{GetType().Name}: finished event processing.");
28-
}
2925

30-
public void OnError(Exception error)
31-
{
26+
public void OnError(Exception error) =>
3227
Console.WriteLine($"{GetType().Name}: experienced error condition.");
33-
}
3428

35-
public void Unsubscribe()
36-
{
29+
public void Unsubscribe() =>
3730
_unsubscriber.Dispose();
38-
}
39-
}
31+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Contracts/ICustomObserver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ public interface ICustomObserver<T> : IObserver<IEvent>
44
where T : IEvent
55
{
66
void Unsubscribe();
7-
}
7+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Contracts/IEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
public interface IEvent
44
{
55
public string Description { get; set; }
6-
}
6+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Contracts/IEventAggregator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public interface IEventAggregator : IObservable<IEvent>
88

99
IDisposable Subscribe<T>(ICustomObserver<T> observer)
1010
where T : IEvent;
11-
}
11+
}

src/AdditionalPatterns/EventAggregator/StoreManagement/Contracts/IPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
public interface IPublisher
44
{
55
void Publish(string payload);
6-
}
6+
}

src/AdditionalPatterns/Interpreter/InterpreterLibrary/SandwichExample/Expressions/Terminal/Breads/WheatBread.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace InterpreterLibrary.SandwichExample.Expressions.Terminal.Breads;
44

55
public class WheatBread : IBread
66
{
7-
public void Interpret(Context context)
8-
{
7+
public void Interpret(Context context) =>
98
context.Output += " Wheat-Bread ";
10-
}
11-
}
9+
}

0 commit comments

Comments
 (0)