# SearchExpressionContext

> This context encapsulate all the datas needed to evaluate a SearchExpression and it allows user to interact with the evaluation runtime of an expression. A SearchExpressionContext is created automatically with a SearchExpressionRuntime anytime SearchExpression.Execute is called.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEditor.Search](/engine/6000.7/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor

```csharp
public readonly struct SearchExpressionContext
```

## Remarks

Here is an example showing ow the SearchExpressionContext is used during evaluation:

## Examples

```csharp
[SearchExpressionEvaluator(SearchExpressionType.Iterable | SearchExpressionType.Variadic)]
[SearchExpressionEvaluatorSignatureOverload(SearchExpressionType.Number, SearchExpressionType.Iterable | SearchExpressionType.Variadic)]
[Description("Extract and returns the X first results for each expression.")]
public static IEnumerable<SearchItem> TakeXFirst(SearchExpressionContext c)
{
    var argIndex = 0;
    var takeNumber = 1;
    if (c.args[0].types.HasFlag(SearchExpressionType.Number))
    {
        ++argIndex;
        takeNumber = Math.Max((int)(c.args[0].GetNumberValue(takeNumber)), 0);
    }

    for ( ; argIndex < c.args.Length; ++argIndex)
    {
        var iterable = c.args[argIndex].Execute(c);
        var taken = 0;
        foreach (var item in iterable)
        {
            if (item == null)
                yield return null;
            else
            {
                yield return item;
                ++taken;
                if (taken == takeNumber)
                {
                    c.Break();
                    break;
                }
            }
        }
    }
}
```

## Fields

| Value                                                                                                  | Description                                                                                                                                                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [args](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/args.md)             | Arguments of passed to the [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md) being evaluated.                                                                                                                                                                                                          |
| [expression](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/expression.md) | \[\[]SearchExpression] being evaluated.                                                                                                                                                                                                                                                                                                         |
| [runtime](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/runtime.md)       | [SearchExpressionRuntime](/engine/6000.7/script-reference/unityeditor/search/searchexpressionruntime.md)  associated with this context. The runtime stores all runtime data (stack frames, stack of contex and items) necessary for evaluation of a [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md). |

## Properties

| Property                                                                                       | Description                                                                                                                                                                                                           |
| ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [items](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/items.md)   | [SearchItem](/engine/6000.7/script-reference/unityeditor/search/searchitem.md)s yielded by the evaluation of a searchExpression.                                                                                      |
| [search](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/search.md) | SearchContex containing the search query that was parsed to create the [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md).                                                    |
| [valid](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/valid.md)   | Is the current context valid or not. If invalid it means the associated [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md) is null or the SearchExiressionRuntime is invalid. |

## Methods

| Method                                                                                                                       | Description                                                                                                                                                                                                                                                                                                                 |
| ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Break](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/break.md)                                 | Break the evaluation of a [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md) meaning items won't be yielded anymore.                                                                                                                                                                |
| [Continue](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/continue.md)                           | Tell [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md) evaluation to continue.                                                                                                                                                                                                     |
| [IsBreaking](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/isbreaking.md)                       | Has the current context being flagged to break execution?                                                                                                                                                                                                                                                                   |
| [IsContinuing](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/iscontinuing.md)                   | Has the current context being flagged to continue execution?                                                                                                                                                                                                                                                                |
| [ResetIterationControl](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/resetiterationcontrol.md) | Restart evaluation and iteration of [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md).                                                                                                                                                                                             |
| [ResolveAlias](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/resolvealias.md)                   | Try to resolve an alias value using the [SearchExpressionRuntime](/engine/6000.7/script-reference/unityeditor/search/searchexpressionruntime.md) attached to this context. Each frame if asked to resolve a [SearchExpression.alias](/engine/6000.7/script-reference/unityeditor/search/searchexpression/alias.md).         |
| [ThrowError](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/throwerror.md)                       | Stop a [SearchExpression](/engine/6000.7/script-reference/unityeditor/search/searchexpression.md) evaluation by throwing a SearchExceptionEvaluatorException. User writing an evaluator can decide to throw thse exceptions if the parameters passed to evaluation are not valid or if a problem happens during evaluation. |
| [ToString](/engine/6000.7/script-reference/unityeditor/search/searchexpressioncontext/tostring.md)                           | Get string representation of a context.                                                                                                                                                                                                                                                                                     |
