Skip to content

Commit

Permalink
chore: add TryGetValue extensions for bindings (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean authored Mar 26, 2024
1 parent f5529e0 commit 581f680
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Kafka/KafkaChannelBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Bindings.Kafka
{
using System;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Bindings.Kafka;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;

Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Kafka/TopicConfigurationObject.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Models.Bindings.Kafka
namespace LEGO.AsyncAPI.Bindings.Kafka
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

Expand Down
27 changes: 27 additions & 0 deletions src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ namespace LEGO.AsyncAPI.Models
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

public static class BindingExtensions

Check warning on line 10 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI)

Check warning on line 10 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI.Bindings)

Check warning on line 10 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Check warning on line 10 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI.Readers)

Check warning on line 10 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

File name should match first type name.
{
public static bool TryGetValue<TBinding>(this AsyncApiBindings<IServerBinding> bindings, out IServerBinding binding)
where TBinding : IServerBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IChannelBinding> bindings, out IChannelBinding binding)
where TBinding : IChannelBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IOperationBinding> bindings, out IOperationBinding binding)
where TBinding : IOperationBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}

public static bool TryGetValue<TBinding>(this AsyncApiBindings<IMessageBinding> bindings, out IMessageBinding binding)
where TBinding : IMessageBinding
{
return bindings.TryGetValue(Activator.CreateInstance<TBinding>().BindingKey, out binding);
}
}

public class AsyncApiBindings<TBinding> : Dictionary<string, TBinding>, IAsyncApiReferenceable

Check warning on line 37 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI)

Check warning on line 37 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI.Bindings)

Check warning on line 37 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Check warning on line 37 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / Publish NuGet packages (LEGO.AsyncAPI.Readers)

Check warning on line 37 in src/LEGO.AsyncAPI/Models/AsyncApiBindings.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

File may only contain a single type
where TBinding : IBinding
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace LEGO.AsyncAPI.Tests.Bindings.Kafka
{
using System.Collections.Generic;
using FluentAssertions;
using LEGO.AsyncAPI.Bindings;
using LEGO.AsyncAPI.Bindings.Kafka;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Bindings.Kafka;
using LEGO.AsyncAPI.Readers;
using NUnit.Framework;
using System.Collections.Generic;

internal class KafkaBindings_Should
{
Expand Down

0 comments on commit 581f680

Please sign in to comment.