Reputation: 15670
I have the following code that works fine as is - aka no errors and it builds / runs:
if (featureManager.IsEnabledAsync("FeatureToggleABC").Result)
{
backgroundTask.Run<NewToggleUserTask>(u => u.AddUserIntoGroup(userName, groupName, connParam));
return "Running task with new toggle";
}
Per Microsoft, it's best NOT to use strings for toggle names incase we finger fumble. It will just assume that the name is still a legit toggle, and set the value to false.
So I've created an enum like this:
namespace Widgets.Enums
{
public enum WidgetFeatureFlags
{
FeatureToggleABC
}
}
And i've tried to change the if statement to look like this:
if (featureManager.IsEnabledAsync(nameof(WidgetFeatureFlags.FeatureToggleABC)).Result)
{
backgroundTask.Run<NewToggleUserTask>(u => u.AddUserIntoGroup(userName, groupName, connParam));
return "Running task with new toggle";
}
But I'm getting an error that says:
Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'bool'
This works:
var featureName = nameof(WidgetFeatureFlags.FeatureToggleABC);
if (featureManager.IsEnabledAsync(featureName).Result)
{
I'm sure it's something simple I've missed but I haven't been able to resolve it. I've tried casting the results but so far no dice.
EDIT 1
Method signatures:
Task<bool> IsEnabledAsync(string feature);
And the method that calls IsEnabledAsync:
public string GetUserMember(string userName, string groupName, string tName)
Edit 2
The featureManager is created using this IFeatureManager class:
namespace Microsoft.FeatureManagement
{
//
// Summary:
// Used to evaluate whether a feature is enabled or disabled.
public interface IFeatureManager
{
IAsyncEnumerable<string> GetFeatureNamesAsync();
Task<bool> IsEnabledAsync(string feature);
Task<bool> IsEnabledAsync<TContext>(string feature, TContext context);
}
}
Upvotes: 0
Views: 208