Table of Contents

Class Template<TInput, TResult>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

A helper class to build a JSON command from a string with tag replacement

public class Template<TInput, TResult> : Template where TInput : IEntity

Type Parameters

TInput

The input type

TResult

The output type

Inheritance
Template<TInput, TResult>
Derived
Inherited Members

Constructors

Template(string)

Initializes a template with a tagged input string.

public Template(string template)

Parameters

template string

The template string with tags for targeting replacements such as "<Author.Name>"

Methods

Collection<TEntity>()

Gets the collection name of a given entity type and replaces matching tags in the template such as "<EntityName>"

public Template<TInput, TResult> Collection<TEntity>() where TEntity : IEntity

Returns

Template<TInput, TResult>

Type Parameters

TEntity

The type of entity to get the collection name of

Elements(int, Expression<Func<TInput, object?>>)

Turns the given index and expression (of input type) to a path with the filtered positional identifier prepended to the property path like "a.Name" and replaces matching tags in the template such as "<a.Name>"

public Template<TInput, TResult> Elements(int index, Expression<Func<TInput, object?>> expression)

Parameters

index int

0=a 1=b 2=c 3=d and so on...

expression Expression<Func<TInput, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

Elements(Expression<Func<TInput, object?>>)

Turns the given expression (of input type) to a path without any filtered positional identifier prepended to it like "Name" and replaces matching tags in the template such as "<Name>"

public Template<TInput, TResult> Elements(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

ElementsOfResult(int, Expression<Func<TResult, object?>>)

Turns the given index and expression (of output type) to a path with the filtered positional identifier prepended to the property path like "a.Name" and replaces matching tags in the template such as "<a.Name>"

public Template<TInput, TResult> ElementsOfResult(int index, Expression<Func<TResult, object?>> expression)

Parameters

index int

0=a 1=b 2=c 3=d and so on...

expression Expression<Func<TResult, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

ElementsOfResult(Expression<Func<TResult, object?>>)

Turns the given expression (of output type) to a path without any filtered positional identifier prepended to it like "Name" and replaces matching tags in the template such as "<Name>"

public Template<TInput, TResult> ElementsOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

Elements<TOther>(int, Expression<Func<TOther, object?>>)

Turns the given index and expression (of any type) to a path with the filtered positional identifier prepended to the property path like "a.Name" and replaces matching tags in the template such as "<a.Name>"

public Template<TInput, TResult> Elements<TOther>(int index, Expression<Func<TOther, object?>> expression)

Parameters

index int

0=a 1=b 2=c 3=d and so on...

expression Expression<Func<TOther, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

Elements<TOther>(Expression<Func<TOther, object?>>)

Turns the given expression (of any type) to a path without any filtered positional identifier prepended to it like "Name" and replaces matching tags in the template such as "<Name>"

public Template<TInput, TResult> Elements<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

Path(Expression<Func<TInput, object?>>)

Turns the given expression (of input type) to a dotted path like "SomeList.SomeProp" and replaces matching tags in the template such as "< SomeList.SomeProp>"

public Template<TInput, TResult> Path(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PathOfResult(Expression<Func<TResult, object?>>)

Turns the given expression (of output type) to a dotted path like "SomeList.SomeProp" and replaces matching tags in the template such as "< SomeList.SomeProp>"

public Template<TInput, TResult> PathOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

Path<TOther>(Expression<Func<TOther, object?>>)

Turns the given expression (of any type) to a dotted path like "SomeList.SomeProp" and replaces matching tags in the template such as "< SomeList.SomeProp>"

public Template<TInput, TResult> Path<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

Paths(Expression<Func<TInput, object?>>)

Turns the property paths in the given new expression (of input type) into paths like "Prop1.Child1 & Prop2.Child2" and replaces matching tags in the template.

public Template<TInput, TResult> Paths(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => new { x.Prop1.Child1, x.Prop2.Child2 }

Returns

Template<TInput, TResult>

PathsOfResult(Expression<Func<TResult, object?>>)

Turns the property paths in the given new expression (of output type) into paths like "Prop1.Child1 & Prop2.Child2" and replaces matching tags in the template.

public Template<TInput, TResult> PathsOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => new { x.Prop1.Child1, x.Prop2.Child2 }

Returns

Template<TInput, TResult>

Paths<TOther>(Expression<Func<TOther, object?>>)

Turns the property paths in the given new expression (of any type) into paths like "Prop1.Child1 & Prop2.Child2" and replaces matching tags in the template.

public Template<TInput, TResult> Paths<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => new { x.Prop1.Child1, x.Prop2.Child2 }

Returns

Template<TInput, TResult>

Type Parameters

TOther

PosAll(Expression<Func<TInput, object?>>)

Turns the given expression (of input type) to a path with the all positional operator like "Authors.$[].Name" and replaces matching tags in the template such as "< Authors.$[].Name>"

public Template<TInput, TResult> PosAll(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosAllOfResult(Expression<Func<TResult, object?>>)

Turns the given expression (of output type) to a path with the all positional operator like "Authors.$[].Name" and replaces matching tags in the template such as "< Authors.$[].Name>"

public Template<TInput, TResult> PosAllOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosAll<TOther>(Expression<Func<TOther, object?>>)

Turns the given expression (of any type) to a path with the all positional operator like "Authors.$[].Name" and replaces matching tags in the template such as "< Authors.$[].Name>"

public Template<TInput, TResult> PosAll<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

PosFiltered(Expression<Func<TInput, object?>>)

Turns the given expression (of input type) to a positional filtered path like "Authors.$[a].Name" and replaces matching tags in the template such as "< Authors.$[a].Name>"

TIP: Index positions start from [0] which is converted to $[a] and so on.

public Template<TInput, TResult> PosFiltered(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosFilteredOfResult(Expression<Func<TResult, object?>>)

Turns the given expression (of output type) to a positional filtered path like "Authors.$[a].Name" and replaces matching tags in the template such as " < Authors.$[a].Name>"

TIP: Index positions start from [0] which is converted to $[a] and so on.

public Template<TInput, TResult> PosFilteredOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosFiltered<TOther>(Expression<Func<TOther, object?>>)

Turns the given expression (of any type) to a positional filtered path like "Authors.$[a].Name" and replaces matching tags in the template such as "< Authors.$[a].Name

"

TIP: Index positions start from [0] which is converted to $[a] and so on.

public Template<TInput, TResult> PosFiltered<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

PosFirst(Expression<Func<TInput, object?>>)

Turns the given expression (of input type) to a path with the first positional operator like "Authors.$.Name" and replaces matching tags in the template such as "< Authors.$.Name>"

public Template<TInput, TResult> PosFirst(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosFirstOfResult(Expression<Func<TResult, object?>>)

Turns the given expression (of output type) to a path with the first positional operator like "Authors.$.Name" and replaces matching tags in the template such as "< Authors.$.Name>"

public Template<TInput, TResult> PosFirstOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

PosFirst<TOther>(Expression<Func<TOther, object?>>)

Turns the given expression (of any type) to a path with the first positional operator like "Authors.$.Name" and replaces matching tags in the template such as "< Authors.$.Name>"

public Template<TInput, TResult> PosFirst<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.SomeList[0].SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

Properties(Expression<Func<TInput, object?>>)

Turns the property paths in the given new expression (of input type) into names like "PropX & PropY" and replaces matching tags in the template.

public Template<TInput, TResult> Properties(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => new { x.Prop1.PropX, x.Prop2.PropY }

Returns

Template<TInput, TResult>

PropertiesOfResult(Expression<Func<TResult, object?>>)

Turns the property paths in the given new expression (of output type) into names like "PropX & PropY" and replaces matching tags in the template.

public Template<TInput, TResult> PropertiesOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => new { x.Prop1.PropX, x.Prop2.PropY }

Returns

Template<TInput, TResult>

Properties<TOther>(Expression<Func<TOther, object?>>)

Turns the property paths in the given new expression (of any type) into paths like "PropX & PropY" and replaces matching tags in the template.

public Template<TInput, TResult> Properties<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => new { x.Prop1.PropX, x.Prop2.PropY }

Returns

Template<TInput, TResult>

Type Parameters

TOther

Property(Expression<Func<TInput, object?>>)

Turns the given member expression (of input type) into a property name like "SomeProp" and replaces matching tags in the template such as "<SomeProp

"

public Template<TInput, TResult> Property(Expression<Func<TInput, object?>> expression)

Parameters

expression Expression<Func<TInput, object>>

x => x.RootProp.SomeProp

Returns

Template<TInput, TResult>

PropertyOfResult(Expression<Func<TResult, object?>>)

Turns the given member expression (of output type) into a property name like "SomeProp" and replaces matching tags in the template such as "<SomeProp

"

public Template<TInput, TResult> PropertyOfResult(Expression<Func<TResult, object?>> expression)

Parameters

expression Expression<Func<TResult, object>>

x => x.RootProp.SomeProp

Returns

Template<TInput, TResult>

Property<TOther>(Expression<Func<TOther, object?>>)

Turns the given member expression (of any type) into a property name like "SomeProp" and replaces matching tags in the template such as "<SomeProp>"

public Template<TInput, TResult> Property<TOther>(Expression<Func<TOther, object?>> expression)

Parameters

expression Expression<Func<TOther, object>>

x => x.RootProp.SomeProp

Returns

Template<TInput, TResult>

Type Parameters

TOther

Tag(string, string)

Replaces the given tag in the template like "<search_term>" with the supplied value.

public Template<TInput, TResult> Tag(string tagName, string replacementValue)

Parameters

tagName string

The tag name without the surrounding < and >

replacementValue string

The value to replace with

Returns

Template<TInput, TResult>

ToArrayFilters()

Executes the tag replacement and returns array filter definitions.

TIP: if all the tags don't match, an exception will be thrown.

public IEnumerable<ArrayFilterDefinition> ToArrayFilters()

Returns

IEnumerable<ArrayFilterDefinition>

ToPipeline()

Executes the tag replacement and returns a pipeline definition.

TIP: if all the tags don't match, an exception will be thrown.

public PipelineDefinition<TInput, TResult> ToPipeline()

Returns

PipelineDefinition<TInput, TResult>