Table of Contents

Class Input

Namespace
Rego
Assembly
Rego.dll

The Input class allows the creation of inputs to a policy without requiring serialization to JSON. The interface is that of a stack, in which values are pushed and then various operations are used to turn terminal types into more complex ones like objects and arrays. When used, the Input will provide the top of the stack to any downstream consumer (such as SetInput(Input)).

public class Input
Inheritance
Input
Inherited Members

Examples

Interpreter rego = new();
var input = Input.Create(new Dictionary<string, object>{
    { "a", 10 },
    { "b", "20" },
    { "c", 30.0 },
    { "d", true }
});

rego.SetInput(input);
Console.WriteLine(rego.Query("input.a"));
// {"expressions":[10]}

Constructors

Input()

Creates an empty input.

public Input()

Properties

Handle

The underlying pointer in the native library.

public RegoInputHandle Handle { get; }

Property Value

RegoInputHandle

Node

Node object representing the input.

public Node Node { get; }

Property Value

Node

Size

Number of elements in the Input stack.

public uint Size { get; }

Property Value

uint

Methods

Array(uint)

Take the top size values on the stack and turn them into an array. Stack order will be used.

public Input Array(uint size)

Parameters

size uint

Number of values to use

Returns

Input

A reference to this input

Boolean(bool)

Push a boolean onto the stack.

public Input Boolean(bool value)

Parameters

value bool

value

Returns

Input

A reference to this input

Create(object)

Factory function which creates Inputs from objects. Supported are any object that can map to JSON, including scalar types such as:

  • int
  • long
  • float
  • double
  • string
  • bool
  • IDictionary
  • IList
public static Input Create(object value)

Parameters

value object

Object to encode as an input

Returns

Input

A reference to the input

Float(double)

Push a float onto the stack.

public Input Float(double value)

Parameters

value double

value

Returns

Input

A reference to this input

Int(long)

Push an integer onto the stack.

public Input Int(long value)

Parameters

value long

value

Returns

Input

A reference to this input

Null()

Push a null onto the stack.

public Input Null()

Returns

Input

A reference to this input

Object(uint)

Take the top size values on the stack and turn them into an object. Note that all of these values must be object items in order for this to be valid.

public Input Object(uint size)

Parameters

size uint

Number of object items to use

Returns

Input

A reference to this input

ObjectItem()

Take the top two values on the stack and turn them into an object item. The penultimate value on the stack will be used as the key, and the top of the stack will be the value for that key. Objects are constructed from object items.

public Input ObjectItem()

Returns

Input

A reference to this input

Set(uint)

Take the top size values on the stack and turn them into an array. Identical items will be de-duplicated.

public Input Set(uint size)

Parameters

size uint

Number of values to use

Returns

Input

A reference to this input

String(string)

Push a string onto the stack.

public Input String(string value)

Parameters

value string

value

Returns

Input

A reference to this input