LaunchDarkly Dotnet Client SDK
Search Results for

    Show / Hide Table of Contents

    Class ContextMultiBuilder

    A mutable object that uses the builder pattern to specify properties for a Context.

    Inheritance
    object
    ContextMultiBuilder
    Inherited Members
    object.GetType()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: LaunchDarkly.Sdk
    Assembly: LaunchDarkly.CommonSdk.dll
    Syntax
    public sealed class ContextMultiBuilder
    Remarks

    Use this type if you need to construct a Context that has multiple Kind values, each with its own nested Context. To define a single-kind context, use Builder(string).

    Obtain an instance of ContextMultiBuilder by calling MultiBuilder(); then, call Add(Context) to specify the nested Context for each kind. Add returns a reference to the same builder, so calls can be chained:

    var context = Context.MultiBuilder().
        Add(Context.New("my-user-key")).
        Add(Context.Builder("my-org-key").Kind("organization").Build()).
        Build();

    A ContextMultiBuilder should not be accessed by multiple threads at once. Once you have called Build(), the resulting Context is immutable and is safe to use from multiple threads. Instances created with Build() are not affected by subsequent actions taken on the builder.

    Constructors

    ContextMultiBuilder()

    Declaration
    public ContextMultiBuilder()

    Methods

    Add(Context)

    Adds a nested Context for a specific kind to a MultiBuilder.

    Declaration
    public ContextMultiBuilder Add(Context context)
    Parameters
    Type Name Description
    Context context

    the context to add

    Returns
    Type Description
    ContextMultiBuilder

    the builder

    Remarks

    It is invalid to add more than one Context with the same kind, or to add a Context that is itself invalid. This error is detected when you call Build().

    If the nested context is multi-kind, this is exactly equivalent to adding each of the individual kinds from it separately. For instance, in the following example, "multi1" and "multi2" end up being exactly the same:

    var c1 = Context.New(ContextKind.Of("kind1"), "key1");
    var c2 = Context.New(ContextKind.Of("kind2"), "key2");
    var c3 = Context.New(ContextKind.Of("kind3"), "key3");
    

    var multi1 = Context.MultiBuilder().Add(c1).Add(c2).Add(c3).Build();

    var c1plus2 = Context.MultiBuilder().Add(c1).Add(c2).Build(); var multi2 = Context.MultiBuilder().Add(c1plus2).Add(c3).Build();

    Build()

    Creates a Context from the current Builder properties.

    Declaration
    public Context Build()
    Returns
    Type Description
    Context

    a new Context

    Remarks

    The Context is immutable and will not be affected by any subsequent actions on the ContextBuilder.

    It is possible for a ContextMultiBuilder to represent an invalid state. Instead of throwing an exception, the ContextMultiBuilder always returns a Context and you can check Error to see if it has an error. See Error for more information about invalid Context conditions. If you pass an invalid Context to an SDK method, the SDK will detect this and will generally log a description of the error.

    If only one context kind was added to the builder, Build returns a single-kind Context rather than a multi-kind Context.

    See Also

    NewMulti(params Context[])
    In this article
    Back to top Generated by DocFX