Class Template
A helper class to build a JSON command from a string with tag replacement
Inherited Members
Namespace: MongoDB.Entities
Assembly: MongoDB.Entities.dll
Syntax
public class Template
Constructors
Template(String)
Initialize a command builder with the supplied template string.
Declaration
public Template(string template)
Parameters
Type | Name | Description |
---|---|---|
String | template | The template string with tags for targeting replacements such as "<Author.Name>" |
Methods
AppendStage(String)
Appends a pipeline stage json string to the current pipeline.
This method can only be used if the template was initialized with an array of pipeline stages.
If this is going to be the first stage of your pipeline, you must instantiate the template with an empty array string new Template("[]")
WARNING: Appending stages prevents this template from being cached!!!
Declaration
public void AppendStage(string pipelineStageString)
Parameters
Type | Name | Description |
---|---|---|
String | pipelineStageString | The pipeline stage json string to append |
Collection<TEntity>()
Gets the collection name of a given entity type and replaces matching tags in the template such as "<EntityName>"
Declaration
public Template Collection<TEntity>()
where TEntity : IEntity
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
TEntity | The type of entity to get the collection name of |
Elements<T>(Int32, Expression<Func<T, Object>>)
Turns the given index and expression into 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>"
Declaration
public Template Elements<T>(int index, Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | 0=a 1=b 2=c 3=d and so on... |
Expression<Func<T, Object>> | expression | x => x.SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
Elements<T>(Expression<Func<T, Object>>)
Turns the given expression into a path without any filtered positional identifier prepended to it like "Name" and replaces matching tags in the template such as "<Name>"
Declaration
public Template Elements<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
Path<T>(Expression<Func<T, Object>>)
Turns the given expression into a dotted path like "SomeList.SomeProp" and replaces matching tags in the template such as "<SomeList.SomeProp>"
Declaration
public Template Path<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.SomeList[0].SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
Paths<T>(Expression<Func<T, Object>>)
Turns the property paths in the given new
expression into paths like "Prop1.Child1 & Prop2.Child2" and replaces matching tags in the template.
Declaration
public Template Paths<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => new { x.Prop1.Child1, x.Prop2.Child2 } |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
PosAll<T>(Expression<Func<T, Object>>)
Turns the given expression into a path with the all positional operator like "Authors.\([].Name" and replaces matching tags in the template such as "<Authors.\)[].Name>"
Declaration
public Template PosAll<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.SomeList[0].SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
PosFiltered<T>(Expression<Func<T, Object>>)
Turns the given expression into 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.
Declaration
public Template PosFiltered<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.SomeList[0].SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
PosFirst<T>(Expression<Func<T, Object>>)
Turns the given expression into a path with the first positional operator like "Authors.\(.Name" and replaces matching tags in the template such as "<Authors.\).Name>"
Declaration
public Template PosFirst<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.SomeList[0].SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
Properties<T>(Expression<Func<T, Object>>)
Turns the property paths in the given new
expression into property names like "PropX & PropY" and replaces matching tags in the template.
Declaration
public Template Properties<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => new { x.Prop1.PropX, x.Prop2.PropY } |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
Property<T>(Expression<Func<T, Object>>)
Turns the given member expression into a property name like "SomeProp" and replaces matching tags in the template such as "<SomeProp>"
Declaration
public Template Property<T>(Expression<Func<T, object>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | expression | x => x.RootProp.SomeProp |
Returns
Type | Description |
---|---|
Template |
Type Parameters
Name | Description |
---|---|
T |
RenderToString()
Executes the tag replacement and returns a string.
TIP: if all the tags don't match, an exception will be thrown.
Declaration
public string RenderToString()
Returns
Type | Description |
---|---|
String |
Tag(String, String)
Replaces the given tag in the template like "<search_term>" with the supplied value.
Declaration
public Template Tag(string tagName, string replacementValue)
Parameters
Type | Name | Description |
---|---|---|
String | tagName | The tag name without the surrounding < and > |
String | replacementValue | The value to replace with |
Returns
Type | Description |
---|---|
Template |
ToArrayFilters<T>()
Executes the tag replacement and returns array filter definitions.
TIP: if all the tags don't match, an exception will be thrown.
Declaration
public IEnumerable<ArrayFilterDefinition> ToArrayFilters<T>()
Returns
Type | Description |
---|---|
IEnumerable<ArrayFilterDefinition> |
Type Parameters
Name | Description |
---|---|
T |
ToPipeline<TInput, TOutput>()
Executes the tag replacement and returns a pipeline definition.
TIP: if all the tags don't match, an exception will be thrown.
Declaration
public PipelineDefinition<TInput, TOutput> ToPipeline<TInput, TOutput>()
Returns
Type | Description |
---|---|
PipelineDefinition<TInput, TOutput> |
Type Parameters
Name | Description |
---|---|
TInput | The input type |
TOutput | The output type |
ToStages()
Executes the tag replacement and returns the pipeline stages as an array of BsonDocuments.
TIP: if all the tags don't match, an exception will be thrown.
Declaration
public IEnumerable<BsonDocument> ToStages()
Returns
Type | Description |
---|---|
IEnumerable<BsonDocument> |
ToString()
Declaration
[Obsolete("Please use the `RenderToString` method instead of `ToString`", true)]
public string ToString()
Returns
Type | Description |
---|---|
String |