Class Template
A helper class to build a JSON command from a string with tag replacement
[SuppressMessage("ReSharper", "MemberCanBeProtected.Global")]
public class Template
- Inheritance
-
Template
- Derived
- Inherited Members
Constructors
Template(string)
Initialize a command builder with the supplied template string.
public Template(string template)
Parameters
templatestringThe 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!!!
public void AppendStage(string pipelineStageString)
Parameters
pipelineStageStringstringThe 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>"
public Template Collection<TEntity>() where TEntity : IEntity
Returns
Type Parameters
TEntityThe type of entity to get the collection name of
Elements<T>(int, 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>"
public Template Elements<T>(int index, Expression<Func<T, object?>> expression)
Parameters
indexint0=a 1=b 2=c 3=d and so on...
expressionExpression<Func<T, object>>x => x.SomeProp
Returns
Type Parameters
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>"
public Template Elements<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.SomeProp
Returns
Type Parameters
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>"
public Template Path<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.SomeList[0].SomeProp
Returns
Type Parameters
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.
public Template Paths<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => new { x.Prop1.Child1, x.Prop2.Child2 }
Returns
Type Parameters
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
"
public Template PosAll<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.SomeList[0].SomeProp
Returns
Type Parameters
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.
public Template PosFiltered<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.SomeList[0].SomeProp
Returns
Type Parameters
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
"
public Template PosFirst<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.SomeList[0].SomeProp
Returns
Type Parameters
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.
public Template Properties<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => new { x.Prop1.PropX, x.Prop2.PropY }
Returns
Type Parameters
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>"
public Template Property<T>(Expression<Func<T, object?>> expression)
Parameters
expressionExpression<Func<T, object>>x => x.RootProp.SomeProp
Returns
Type Parameters
T
RenderToString()
Executes the tag replacement and returns a string.
TIP: if all the tags don't match, an exception will be thrown.
public string RenderToString()
Returns
Tag(string, string)
Replaces the given tag in the template like "<search_term>" with the supplied value.
public Template Tag(string tagName, string replacementValue)
Parameters
tagNamestringThe tag name without the surrounding < and >
replacementValuestringThe value to replace with
Returns
ToArrayFilters<T>()
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<T>()
Returns
- IEnumerable<ArrayFilterDefinition>
Type Parameters
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.
public PipelineDefinition<TInput, TOutput> ToPipeline<TInput, TOutput>()
Returns
- PipelineDefinition<TInput, TOutput>
Type Parameters
TInputThe input type
TOutputThe 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.
public IEnumerable<BsonDocument> ToStages()
Returns
- IEnumerable<BsonDocument>