Class ILdClientExtensions
Convenience methods that extend the ILdClient interface.
Inherited Members
Namespace: LaunchDarkly.Sdk.Client
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public static class ILdClientExtensions
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 toclient.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
| Edit this page View SourceEnumVariationDetail<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
Parameters
Type | Name | Description |
---|---|---|
ILdClient | client | the client instance |
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.
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
Parameters
Type | Name | Description |
---|---|---|
ILdClient | client | the client instance |
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 |
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
[Obsolete("User has been superseded by Context. See ILdClient.Identify(Context, TimeSpan)")]
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 |
TimeSpan | maxWaitTime | the maximum time to wait for the new flag values |
Returns
Type | Description |
---|---|
bool | true if new flag values were obtained |
Remarks
This is equivalent to Identify(Context, TimeSpan), but using the User type instead of Context.
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
[Obsolete("User has been superseded by Context. See ILdClient.Identify(Context, TimeSpan)")]
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 |
---|---|
Task<bool> | 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.