Merge pull request #207 from richardbuckle/fix/deserialization

Fix/deserialization
This commit is contained in:
Jochen Kühner 2020-01-10 06:15:48 +01:00 коммит произвёл GitHub
Родитель 9ecaeb031c f0d33ebc3c
Коммит 8fca62270d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,32 @@
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using Newtonsoft.Json;
using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Tests.Highlighting
{
[TestFixture]
public class DeserializationTests
{
TextDocument document;
DocumentHighlighter highlighter;
[SetUp]
public void SetUp()
{
document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();");
highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#"));
}
[Test]
public void TestRoundTripColor()
{
HighlightingColor color = highlighter.GetNamedColor("Comment");
string jsonString = JsonConvert.SerializeObject(color);
HighlightingColor color2 = JsonConvert.DeserializeObject<HighlightingColor>(jsonString);
Assert.AreEqual(color, color2);
}
}
}

Просмотреть файл

@ -22,6 +22,7 @@
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
</ItemGroup>

Просмотреть файл

@ -196,8 +196,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting
this.Underline = info.GetBoolean("Underline");
if (info.GetBoolean("HasStrikethrough"))
this.Strikethrough = info.GetBoolean("Strikethrough");
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush));
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush));
this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(SimpleHighlightingBrush));
this.Background = (HighlightingBrush)info.GetValue("Background", typeof(SimpleHighlightingBrush));
if (info.GetBoolean("HasFamily"))
this.FontFamily = new FontFamily(info.GetString("Family"));
if (info.GetBoolean("HasSize"))
@ -222,6 +222,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
info.AddValue("HasUnderline", this.Underline.HasValue);
if (this.Underline.HasValue)
info.AddValue("Underline", this.Underline.Value);
info.AddValue("HasStrikethrough", this.Strikethrough.HasValue);
if (this.Strikethrough.HasValue)
info.AddValue("Strikethrough", this.Strikethrough.Value);
info.AddValue("Foreground", this.Foreground);