Show / Hide Table of Contents

Class ILdClientExtensions

Convenience methods that extend the ILdClient interface.

Inheritance
System.Object
ILdClientExtensions
Namespace: LaunchDarkly.Sdk.Client
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public static class ILdClientExtensions : Object
Remarks

These allow you to do the following:

  • Treat a string-valued flag as if it referenced values of an enum type.
  • Call ILdClient methods with the User type instead of Context. The SDK's preferred type for identifying an evaluation context, is Context; older versions of the SDK used only the simpler User model. These extension methods provide backward compatibility with application code that used the User type. Each of them simply converts the User to a Context with FromUser(User) and calls the equivalent ILdClient method. For instance, client.Identify(user) is exactly equivalent to client.Identify(Context.FromUser(user)).

These are implemented outside of ILdClient and LdClient because they do not rely on any implementation details of LdClient; they are decorators that would work equally well with a stub or test implementation of the interface.

Methods

EnumVariation<T>(ILdClient, String, T)

Equivalent to StringVariation(String, String), but converts the flag's string value to an enum value.

Declaration
public static T EnumVariation<T>(this ILdClient client, string key, T defaultValue)
    where T : struct, Enum, ValueType
Parameters
Type Name Description
ILdClient client

the client instance

System.String key

the unique feature key for the feature flag

T defaultValue

the default value of the flag (as an enum value)

Returns
Type Description
T

the variation for the given user, or defaultValue if the flag cannot be evaluated or does not have a valid enum value

Type Parameters
Name Description
T

the enum type

Remarks

If the flag has a value that is not one of the allowed enum value names, or is not a string, defaultValue is returned.

EnumVariationDetail<T>(ILdClient, String, T)

Equivalent to StringVariationDetail(String, String), but converts the flag's string value to an enum value.

Declaration
public static EvaluationDetail<T> EnumVariationDetail<T>(this ILdClient client, string key, T defaultValue)
    where T : struct, Enum, ValueType
Parameters
Type Name Description
ILdClient client

the client instance

System.String key

the unique feature key for the feature flag

T defaultValue

the default value of the flag (as an enum value)

Returns
Type Description
EvaluationDetail<T>

an EvaluationDetail<T> object

Type Parameters
Name Description
T

the enum type

Remarks

If the flag has a value that is not one of the allowed enum value names, or is not a string, defaultValue is returned.

Identify(ILdClient, User, TimeSpan)

Changes the current user, requests flags for that user from LaunchDarkly if we are online, and generates an analytics event to tell LaunchDarkly about the user.

Declaration
public static bool Identify(this ILdClient client, User user, TimeSpan maxWaitTime)
Parameters
Type Name Description
ILdClient client

the client instance

User user

the user; should not be null (a null reference will cause an error to be logged and no event will be sent

System.TimeSpan maxWaitTime

the maximum time to wait for the new flag values

Returns
Type Description
System.Boolean

true if new flag values were obtained

Remarks

This is equivalent to Identify(Context, TimeSpan), but using the User type instead of Context.

See Also
Identify(Context, System.TimeSpan)

IdentifyAsync(ILdClient, User)

Changes the current user, requests flags for that user from LaunchDarkly if we are online, and generates an analytics event to tell LaunchDarkly about the user.

Declaration
public static Task<bool> IdentifyAsync(this ILdClient client, User user)
Parameters
Type Name Description
ILdClient client

the client instance

User user

the user; should not be null (a null reference will cause an error to be logged and no event will be sent

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

a task that yields true if new flag values were obtained

Remarks

This is equivalent to IdentifyAsync(Context), but using the User type instead of Context.

See Also
Identify(Context, System.TimeSpan)
In This Article
Back to top Generated by DocFX