Struct MemoryTemplate<T>
Represents generic template for buffer rendering.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public struct MemoryTemplate<T>
where T : IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the memory. |
Remarks
This type is aimed to fast replacement of the sequence of elements called placeholder in the original sequence of elements. In other words, it is an implementation of find-and-replace algorithm. Pre-compiled template allows to reuse it when rendering with different arguments is required. The rendering process is much faster than Format(String, Object[]) especially for large templates. However, the rendering process doesn't offer formatting procedures.
Constructors
| Improve this Doc View SourceMemoryTemplate(ReadOnlyMemory<T>, ReadOnlySpan<T>)
Initializes a new pre-compiled template.
Declaration
public MemoryTemplate(ReadOnlyMemory<T> template, ReadOnlySpan<T> placeholder)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<T> | template | The template containing placeholders for replacement. |
ReadOnlySpan<T> | placeholder | The span of elements representing template placeholder. |
Properties
| Improve this Doc View SourceValue
Gets original template passed to this object during construction.
Declaration
public ReadOnlyMemory<T> Value { get; }
Property Value
Type | Description |
---|---|
ReadOnlyMemory<T> |
Methods
| Improve this Doc View SourceRender<TWriter>(TWriter, Action<Int32, TWriter>)
Replaces all placeholders in the template with custom content.
Declaration
public void Render<TWriter>(TWriter output, Action<int, TWriter> rewriter)
where TWriter : class, IBufferWriter<T>
Parameters
Type | Name | Description |
---|---|---|
TWriter | output | The buffer writer used to build rendered content. |
Action<Int32, TWriter> | rewriter | The action responsible for replacing placeholder with custom content. The first argument of the action indicates placeholder index. |
Type Parameters
Name | Description |
---|---|
TWriter | The type of the buffer writer. |
Render<TArg>(TArg, Action<Int32, TArg>, ReadOnlySpanAction<T, TArg>)
Replaces all placeholders in the template with custom content.
Declaration
public void Render<TArg>(TArg arg, Action<int, TArg> rewriter, ReadOnlySpanAction<T, TArg> output)
Parameters
Type | Name | Description |
---|---|---|
TArg | arg | The argument to be passed to the write actions. |
Action<Int32, TArg> | rewriter | The action responsible for replacing placeholder with custom content. The first argument of the action indicates placeholder index. |
ReadOnlySpanAction<T, TArg> | output | The action responsible for writing unmodified segments from the original template. |
Type Parameters
Name | Description |
---|---|
TArg | The type of the argument to be passed to |