-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCharacter.cs
48 lines (37 loc) · 1.73 KB
/
Character.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using static System.Runtime.CompilerServices.MethodImplOptions;
namespace Plato
{
/// <summary>
/// A simple wrapper around the built-in <c>char</c> type.
/// </summary>
[DataContract]
public partial struct Character
{
// -------------------------------------------------------------------------------
// Field
// -------------------------------------------------------------------------------
[DataMember] public readonly char Value;
// -------------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------------
[MethodImpl(AggressiveInlining)]
public Character(char value) => Value = value;
// -------------------------------------------------------------------------------
// Conversions
// -------------------------------------------------------------------------------
[MethodImpl(AggressiveInlining)]
public char ToSystem() => Value;
[MethodImpl(AggressiveInlining)]
public static Character FromSystem(char c) => new(c);
[MethodImpl(AggressiveInlining)]
public static implicit operator Character(char c) => FromSystem(c);
[MethodImpl(AggressiveInlining)]
public static implicit operator char(Character c) => c.ToSystem();
[MethodImpl(AggressiveInlining)]
public static implicit operator Character(Integer n) => FromSystem((char)n.Value);
[MethodImpl(AggressiveInlining)]
public static implicit operator Integer(Character c) => c.ToSystem();
}
}