Closed DamianEdwards closed 1 year ago
Hi Damian! I had a quick question about the best way to implement this.
My initial idea was to use StringWriter
like the following:
public static ValueTask RenderAsync(this RazorSlice slice, StringBuilder stringBuilder, HtmlEncoder? htmlEncoder = null)
{
using var sw = new StringWriter(stringBuilder);
var task = slice.RenderAsync(sw, htmlEncoder);
if (task.IsCompletedSuccessfully)
{
return ValueTask.CompletedTask;
}
return task;
}
However, I'm not entirely sure if this is the most efficient approach. Do you have any recommendations?
I think that's a fine approach. While it's going through a few layers (IBufferWriter<byte>
-> TextWriter
-> StringWriter
-> StringBuilder
) they should all be simply passing along to the next layer as much as possible.
You should be able to just return the task result of calling RenderAsync
directly though, no need for the IsCompletedSuccessfully
check as you don't need to go async.
Thank you for your response! I will proceed with the StringWriter
approach. May I submit a pull request for this feature? Please let me know if you have any further suggestions or requirements for the implementation.
Please go ahead!
This was done and shipped in v0.6.0
E.g.