forked from LEGO/AsyncAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBindingExtensions.cs
More file actions
62 lines (53 loc) · 2.03 KB
/
Copy pathBindingExtensions.cs
File metadata and controls
62 lines (53 loc) · 2.03 KB
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
55
56
57
58
59
60
61
62
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Models
{
using System;
using LEGO.AsyncAPI.Models.Interfaces;
public static class BindingExtensions
{
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IServerBinding> bindings, out TBinding binding)
where TBinding : class, IServerBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var serverBinding))
{
binding = serverBinding as TBinding;
return true;
}
binding = default;
return false;
}
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IChannelBinding> bindings, out TBinding binding)
where TBinding : class, IChannelBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var channelBinding))
{
binding = channelBinding as TBinding;
return true;
}
binding = default;
return false;
}
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IOperationBinding> bindings, out TBinding binding)
where TBinding : class, IOperationBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var operationBinding))
{
binding = operationBinding as TBinding;
return true;
}
binding = default;
return false;
}
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IMessageBinding> bindings, out TBinding binding)
where TBinding : class, IMessageBinding
{
if (bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out var messageBinding))
{
binding = messageBinding as TBinding;
return true;
}
binding = default;
return false;
}
}
}