Skip to content

Commit

Permalink
Merge branch 'main' into doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 31, 2023
2 parents 8763962 + d5d9156 commit 894b653
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 30 deletions.
5 changes: 4 additions & 1 deletion NUGET_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ PeyrSharp is divided in multiple packages:
- Converters
- Internet
- Crypt
- XmlHelper
- JsonHelper

**PeyrSharp.Env**, methods related to the file system and to the current execution environment.

- FileSys
- Logger
- Update
- System
- Update
- UwpApp

**PeyrSharp.Enums**, all enumerations used by PeyrSharp

Expand Down
2 changes: 1 addition & 1 deletion PeyrSharp.Core/Converters/Speeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static class Speeds
public static double MachToKilometersPerHour(double n) =>
// Use the conversion formula: km/h = mach * 1234.8
n * 1234.8;

/// <summary>
/// Converts a speed in mach to miles per hour.
/// </summary>
Expand Down
68 changes: 68 additions & 0 deletions PeyrSharp.Core/JsonHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
MIT License
Copyright (c) Devyus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.IO;
using System.Text.Json;

namespace PeyrSharp.Core
{
/// <summary>
/// A helper class for working with JSON files.
/// </summary>
public static class JsonHelper
{
/// <summary>
/// Saves an object as a JSON file.
/// </summary>
/// <typeparam name="T">The type of the object to save.</typeparam>
/// <param name="obj">The object to save.</param>
/// <param name="fileName">The name of the file to save to.</param>
public static void SaveAsJson<T>(T obj, string fileName)
{
// Convert the object to a JSON string
string json = JsonSerializer.Serialize(obj);

// Write the JSON string to the file
File.WriteAllText(fileName, json);
}

/// <summary>
/// Loads an object from a JSON file.
/// </summary>
/// <typeparam name="T">The type of the object to load.</typeparam>
/// <param name="fileName">The name of the file to load from.</param>
/// <returns>The object loaded from the file.</returns>
public static T LoadFromJson<T>(string fileName)
{
// Read the JSON string from the file
string json = File.ReadAllText(fileName);

// Convert the JSON string to an object of type T
T obj = JsonSerializer.Deserialize<T>(json);

// Return the object
return obj;
}
}
}
15 changes: 7 additions & 8 deletions PeyrSharp.Core/PeyrSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Core</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Authors>Devyus</Authors>
<Description>Core methods and features of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,11 +16,10 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added Range() method in Stats (#117)
- Added Variance() method in Stats (#118)
- Added StandardDeviation() method in Stats (#119)
- Improved exceptions
</PackageReleaseNotes>
<PackageReleaseNotes>- Added Save() method in XmlHelper (#126)
- Added Load() method in XmlHelper (#127)
- Added Save() method in JsonHelper (#128)
- Added Load() method in JsonHelper (#129)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -35,8 +34,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.8.0.2308" />
</ItemGroup>

</Project>
113 changes: 113 additions & 0 deletions PeyrSharp.Core/XmlHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
MIT License
Copyright (c) Devyus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System;
using System.IO;
using System.Xml.Serialization;

namespace PeyrSharp.Core
{
/// <summary>
/// Provides helper methods for loading and saving objects to/from XML files.
/// </summary>
public static class XmlHelper
{
/// <summary>
/// Loads an object of type T from an XML file at the specified path.
/// If the file does not exist, a new instance of type T will be created
/// and saved to the file using the SaveToXml method before returning it.
/// </summary>
/// <typeparam name="T">The type of object to be loaded.</typeparam>
/// <param name="path">The path of the XML file to load or create.</param>
/// <returns>
/// The loaded object of type T if the file exists and can be deserialized successfully,
/// or a new instance of type T if the file does not exist and can be created and saved successfully.
/// If an exception occurs during loading or saving, the method returns <see langword="null"/>.
/// </returns>
public static T? LoadFromXml<T>(string path) where T : new()

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 5.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 6.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on ubuntu-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 48 in PeyrSharp.Core/XmlHelper.cs

View workflow job for this annotation

GitHub Actions / .NET 7.0.x on windows-latest sample

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
try
{
// Check if the file exists
if (File.Exists(path))
{
// Create an XmlSerializer for type T
XmlSerializer serializer = new(typeof(T));

// Create a StreamReader to read from the file
using StreamReader reader = new(path);

// Deserialize the object from the file
T obj = (T)serializer.Deserialize(reader);

// Return the object
return obj;
}
else
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
// Create a new instance of type T
T obj = new();

// Save the object to the file using the SaveToXml method
SaveToXml(obj, path);

// Return the object
return obj;
}
}
catch (Exception ex)
{
// Handle the exception
Console.WriteLine("An error occurred: " + ex.Message);

// Return null if an exception is thrown
return default;
}
}

/// <summary>
/// Saves the specified object of type T to an XML file at the specified path.
/// </summary>
/// <typeparam name="T">The type of object to be saved.</typeparam>
/// <param name="obj">The object to be saved.</param>
/// <param name="path">The path of the XML file to save the object.</param>
/// <returns><see langword="true"/> if the object is successfully serialized and saved to the file; otherwise, <see langword="false"/>.</returns>
public static bool SaveToXml<T>(T obj, string path)
{
// Create an XmlSerializer for type T
XmlSerializer serializer = new(typeof(T));

// Create a StreamWriter to write to the file
StreamWriter writer = new(path);

// Serialize the object to the file
serializer.Serialize(writer, obj);

writer.Dispose();
// Return true if no exception is thrown
return true;
}
}
}
2 changes: 1 addition & 1 deletion PeyrSharp.Enums/PeyrSharp.Enums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/DevyusCode/PeyrSharp</RepositoryUrl>
<PackageTags>enums;c-sharp;dotnet;vb;peyrsharp;leo corp</PackageTags>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
7 changes: 3 additions & 4 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Env</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Authors>Devyus</Authors>
<Description>Environment-related methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,8 +16,7 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added UwpApp record (#120)
- Added the possibility to get UWP apps asynchronously (#120)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,6 +31,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PeyrSharp.Exceptions</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Company>Devyus</Company>
<Description>Exceptions of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand Down
4 changes: 2 additions & 2 deletions PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Extensions</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Authors>Devyus</Authors>
<Description>Extensions methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.UiHelpers</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Authors>Devyus</Authors>
<Description>Useful helpers for Windows Forms and Windows Presentation Framework.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -35,7 +35,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion PeyrSharp/PeyrSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static class PeyrSharp
/// <summary>
/// The current version of PeyrSharp.
/// </summary>
public static string Version => "1.7.0.2307";
public static string Version => "1.8.0.2308";
}
}
19 changes: 11 additions & 8 deletions PeyrSharp/PeyrSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp</Title>
<Version>1.7.0.2307</Version>
<Version>1.8.0.2308</Version>
<Authors>Devyus</Authors>
<Copyright>© 2023</Copyright>
<Description>A C# library designed to make developers' job easier.</Description>
Expand All @@ -17,7 +17,10 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Fixed IsAvailableAsync() crashes when no internet connection is available (#112)</PackageReleaseNotes>
<PackageReleaseNotes>- Added Save() method in XmlHelper (#126)
- Added Load() method in XmlHelper (#127)
- Added Save() method in JsonHelper (#128)
- Added Load() method in JsonHelper (#129)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,12 +35,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Core" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Enums" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Env" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.7.0.2307" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Core" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Env" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.8.0.2308" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.8.0.2308" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ PeyrSharp is divided in multiple packages:
- Converters
- Internet
- Crypt
- XmlHelper
- JsonHelper

</details>

Expand All @@ -64,8 +66,9 @@ PeyrSharp is divided in multiple packages:

- FileSys
- Logger
- Update
- System
- Update
- UwpApp

</details>

Expand Down

0 comments on commit 894b653

Please sign in to comment.