-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHtmlEncodingTextWriterReference.cs
More file actions
30 lines (26 loc) · 1.03 KB
/
Copy pathHtmlEncodingTextWriterReference.cs
File metadata and controls
30 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Eighty.Twenty
{
internal unsafe readonly struct HtmlEncodingTextWriterReference
{
/// <summary>
/// This is a pointer to an HtmlEncodingTextWriter.
/// It's safe to have a pointer to the HtmlEncodingTextWriter, even though it's a managed type (it contains arrays),
/// because it's stored on the stack (so the GC can always reach it) and the pointer won't live longer than
/// the local variable it points to.
/// </summary>
private readonly void* _writer;
public HtmlEncodingTextWriterReference(ref HtmlEncodingTextWriter writer)
{
_writer = Unsafe.AsPointer(ref writer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref HtmlEncodingTextWriter Get()
{
return ref Unsafe.AsRef<HtmlEncodingTextWriter>(_writer);
}
public bool IsDefault() => new IntPtr(_writer) == IntPtr.Zero;
}
}