Skip to content

Commit 8fca622

Browse files
authored
Merge pull request #207 from richardbuckle/fix/deserialization
Fix/deserialization
2 parents 9ecaeb0 + f0d33eb commit 8fca622

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using ICSharpCode.AvalonEdit.Document;
2+
using ICSharpCode.AvalonEdit.Highlighting;
3+
using Newtonsoft.Json;
4+
using NUnit.Framework;
5+
6+
7+
namespace ICSharpCode.AvalonEdit.Tests.Highlighting
8+
{
9+
[TestFixture]
10+
public class DeserializationTests
11+
{
12+
TextDocument document;
13+
DocumentHighlighter highlighter;
14+
15+
[SetUp]
16+
public void SetUp()
17+
{
18+
document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();");
19+
highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#"));
20+
}
21+
22+
[Test]
23+
public void TestRoundTripColor()
24+
{
25+
HighlightingColor color = highlighter.GetNamedColor("Comment");
26+
string jsonString = JsonConvert.SerializeObject(color);
27+
28+
HighlightingColor color2 = JsonConvert.DeserializeObject<HighlightingColor>(jsonString);
29+
Assert.AreEqual(color, color2);
30+
}
31+
}
32+
}

ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<DefineConstants>TRACE</DefineConstants>
2323
</PropertyGroup>
2424
<ItemGroup>
25+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2526
<PackageReference Include="NUnit" Version="3.11.0" />
2627
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
2728
</ItemGroup>

ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ protected HighlightingColor(SerializationInfo info, StreamingContext context)
196196
this.Underline = info.GetBoolean("Underline");
197197
if (info.GetBoolean("HasStrikethrough"))
198198
this.Strikethrough = info.GetBoolean("Strikethrough");
199-
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush));
200-
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush));
199+
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(SimpleHighlightingBrush));
200+
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(SimpleHighlightingBrush));
201201
if (info.GetBoolean("HasFamily"))
202202
this.FontFamily = new FontFamily(info.GetString("Family"));
203203
if (info.GetBoolean("HasSize"))
@@ -222,6 +222,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
222222
info.AddValue("HasUnderline", this.Underline.HasValue);
223223
if (this.Underline.HasValue)
224224
info.AddValue("Underline", this.Underline.Value);
225+
info.AddValue("HasStrikethrough", this.Strikethrough.HasValue);
225226
if (this.Strikethrough.HasValue)
226227
info.AddValue("Strikethrough", this.Strikethrough.Value);
227228
info.AddValue("Foreground", this.Foreground);

0 commit comments

Comments
 (0)