mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-14 04:58:33 +00:00
perf: Disposing text readers
This commit is contained in:
parent
b1b12c76dd
commit
eb7f3033fb
2 changed files with 18 additions and 7 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
#if SIMPLSHARP
|
using System;
|
||||||
|
#if SIMPLSHARP
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using System.IO;
|
using System.IO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ICD.Common.Utils.IO
|
namespace ICD.Common.Utils.IO
|
||||||
{
|
{
|
||||||
public class IcdTextReader
|
public class IcdTextReader : IDisposable
|
||||||
{
|
{
|
||||||
private readonly TextReader m_TextReader;
|
private readonly TextReader m_TextReader;
|
||||||
|
|
||||||
|
|
@ -17,5 +17,10 @@ namespace ICD.Common.Utils.IO
|
||||||
{
|
{
|
||||||
m_TextReader = textReader;
|
m_TextReader = textReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
m_TextReader.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,8 +205,11 @@ namespace ICD.Common.Utils.Json
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
using (JsonTextWriter writer = new JsonTextWriter(new IcdStringWriter(builder).WrappedStringWriter))
|
using (IcdStringWriter stringWriter = new IcdStringWriter(builder))
|
||||||
|
{
|
||||||
|
using (JsonTextWriter writer = new JsonTextWriter(stringWriter.WrappedStringWriter))
|
||||||
serializeMethod(writer);
|
serializeMethod(writer);
|
||||||
|
}
|
||||||
|
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
@ -224,9 +227,12 @@ namespace ICD.Common.Utils.Json
|
||||||
if (deserializeMethod == null)
|
if (deserializeMethod == null)
|
||||||
throw new ArgumentNullException("deserializeMethod");
|
throw new ArgumentNullException("deserializeMethod");
|
||||||
|
|
||||||
using (JsonTextReader reader = new JsonTextReader(new IcdStringReader(json).WrappedStringReader))
|
using (IcdStringReader stringReader = new IcdStringReader(json))
|
||||||
|
{
|
||||||
|
using (JsonTextReader reader = new JsonTextReader(stringReader.WrappedStringReader))
|
||||||
return deserializeMethod(reader);
|
return deserializeMethod(reader);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes to json, wrapping the object with a message property to differentiate between messages.
|
/// Serializes to json, wrapping the object with a message property to differentiate between messages.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue