-
Notifications
You must be signed in to change notification settings - Fork 24
/
NullCapabilities.cs
54 lines (47 loc) · 1.46 KB
/
NullCapabilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Moryx.AbstractionLayer.Capabilities
{
/// <summary>
/// Null object implementation for capabilities to remove null checks.
/// They provide nothing, but are provided by everything
/// </summary>
[DataContract]
public class NullCapabilities : ICapabilities
{
private static NullCapabilities _instance;
/// <summary>
/// Singleton instance
/// </summary>
public static NullCapabilities Instance => _instance ?? (_instance = new NullCapabilities());
/// <summary>
/// Private constructor to enforce singleton
/// </summary>
private NullCapabilities()
{
}
/// <inheritdoc />
public bool IsCombined => false;
/// <summary>
/// <see cref="NullCapabilities"/> are provided by everything
/// </summary>
public bool ProvidedBy(ICapabilities provided)
{
return true;
}
/// <summary>
/// <see cref="NullCapabilities"/> provide nothing, but themselves
/// </summary>
public bool Provides(ICapabilities required)
{
return false;
}
/// <inheritdoc />
public IEnumerable<ICapabilities> GetAll()
{
yield return this;
}
}
}