< Summary

Information
Class: LGDXRobotCloud.Utilities.Helpers.SerialiserHelper
Assembly: LGDXRobotCloud.Utilities
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Utilities/Helpers/SerialiserHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 28
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToBase64(...)0%620%
FromBase64(...)0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Utilities/Helpers/SerialiserHelper.cs

#LineLine coverage
 1using System.Runtime.Serialization;
 2
 3namespace LGDXRobotCloud.Utilities.Helpers;
 4
 5public static class SerialiserHelper
 6{
 7  public static string ToBase64<T>(T obj)
 08  {
 09    if (obj == null) throw new ArgumentNullException(nameof(obj));
 10
 011    var serializer = new DataContractSerializer(typeof(T));
 012    using var ms = new MemoryStream();
 013    serializer.WriteObject(ms, obj);
 14
 015    return Convert.ToBase64String(ms.ToArray());
 016  }
 17
 18  public static T? FromBase64<T>(string base64)
 019  {
 020    if (string.IsNullOrWhiteSpace(base64)) throw new ArgumentNullException(nameof(base64));
 21
 022    var bytes = Convert.FromBase64String(base64);
 023    var serializer = new DataContractSerializer(typeof(T));
 24
 025    using var ms = new MemoryStream(bytes);
 026    return (T?)serializer.ReadObject(ms);
 027  }
 28}