-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathMessageText.cs
More file actions
75 lines (74 loc) · 1.95 KB
/
MessageText.cs
File metadata and controls
75 lines (74 loc) · 1.95 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using SitePlugin;
namespace Common
{
public static class MessagePartFactory
{
public static IMessageText CreateMessageText(string text)
{
return MessageText.New(text);
}
public static IEnumerable<IMessagePart> CreateMessageItems(string text)
{
return new List<IMessagePart>
{
CreateMessageText(text)
};
}
}
public static class MessagePartsTools
{
public static string ToText(this IEnumerable<IMessagePart> items)
{
if (items == null)
{
return null;
}
var list = new List<string>();
foreach (var item in items)
{
if (item is IMessageText text)
{
list.Add(text.Text);
}
else if (item is IMessageLink link)
{
list.Add(link.Text);
}
}
return string.Join("", list);
}
}
internal class MessageText : IMessageText
{
public string Text { get; }
public static MessageText New(string text)
{
#pragma warning disable CS0618 // Type or member is obsolete
return new MessageText(text);
#pragma warning restore CS0618 // Type or member is obsolete
}
public MessageText(string text)
{
Text = text;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (obj is MessageText text)
{
return this.Text.Equals(text.Text);
}
return false;
}
public override string ToString() => Text;
public override int GetHashCode()
{
return Text.GetHashCode();
}
}
}