Skip to content

Commit

Permalink
Add ConverterContextExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
liliankasem committed Jun 27, 2023
1 parent 3fbaf92 commit a867b61
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.Azure.Functions.Worker.Converters
{
/// <summary>
/// Provides extension methods to work with an <see cref="ConverterContext"/> instance.
/// </summary>
public static class ConverterContextExtensions
{
/// <summary>
/// Tries to retrieve the binding attribute from the <see cref="ConverterContext"/>.
/// </summary>
/// <param name="context">The converter context.</param>
/// <param name="bindingAttribute">When this method returns, contains the binding attribute if found; otherwise, <c>null</c>.</param>
/// <returns><c>true</c> if the binding attribute is found in the converter context; otherwise, <c>false</c>.</returns>
public static bool TryGetBindingAttribute(this ConverterContext context, out object? bindingAttribute)
{
if (context.Properties.TryGetValue(PropertyBagKeys.BindingAttribute, out object? value))
{
bindingAttribute = value;
return true;
}

bindingAttribute = null;
return false;
}
}
}

0 comments on commit a867b61

Please sign in to comment.