Show / Hide Table of Contents

Struct MemoryTemplate<T>

Represents generic template for buffer rendering.

Inherited Members
ValueType.Equals(Object)
ValueType.GetHashCode()
ValueType.ToString()
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
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 Source

MemoryTemplate(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 Source

Value

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 Source

Render<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.

| Improve this Doc View Source

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 rewriter and output.

Extension Methods

Sequence.Skip<TEnumerator, T>(ref TEnumerator, Int32)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX