SimpleXMLConfigureFileHelper 1.0.1
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
dotnet add package SimpleXMLConfigureFileHelper --version 1.0.1
NuGet\Install-Package SimpleXMLConfigureFileHelper -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimpleXMLConfigureFileHelper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleXMLConfigureFileHelper --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimpleXMLConfigureFileHelper, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimpleXMLConfigureFileHelper as a Cake Addin
#addin nuget:?package=SimpleXMLConfigureFileHelper&version=1.0.1
// Install SimpleXMLConfigureFileHelper as a Cake Tool
#tool nuget:?package=SimpleXMLConfigureFileHelper&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
How to use
This library can help you easily convert a class to XML file (just property of this class), or read data from XML file. Here are some functions:
/// <summary>
/// Read or create default configure file.
/// If read file not exists, create one by new T object, and this file version will be the param TargetVersion.
/// If read file exists, compare the file version and the param TargetVersion.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="FilePath">File Path</param>
/// <param name="TargetVersion">Target version</param>
/// <returns>Configure class</returns>
/// <exception cref="Exception"></exception>
public static T ReadConfigFile<T>(string FilePath, string TargetVersion = "1.0");
/// <summary>
/// Save configure file, will replace old file.
/// </summary>
/// <param name="ConfigObj"></param>
/// <param name="FilePath"></param>
/// <param name="FileVersion"></param>
public static void SaveConfigFile(object ConfigObj, string FilePath, string FileVersion);
/// <summary>
/// File version
/// </summary>
public static string? FileVersion { get; set; }
Test bench
CS
namespace Test.NET
{
public class Sub1
{
public int S1Value { get; set; }
}
public class Sub2
{
public int S2Value { get; set; }
public List<string> ints { get; set; } = new List<string>() { "sd1", "sd2" };
}
public class TestClass
{
public int vint { get; set; } = 1;
public Int64 vint64 { get; set; } = 2;
public Int32 vint32 { get; set; } = 3;
public Int16 vint16 { get; set; }
public byte vbyte { get; set; } = 255;
public bool vb { get; set; } = false;
public double vdouble { get; set; }
public float vfloat { get; set; } = 2.1F;
public string TestString { get; set; }
public Sub1 Sub1 { get; set; }
public Sub2 Sub2 { get; set; }
public List<int> Ints2 { get; set; } = new List<int>() { 12, 56, 54 };
public List<Sub2> sub2s { get; set; }
public List<Sub2> sub3s { get; set; } = new List<Sub2>() { new Sub2() { S2Value = 1 }, new Sub2() { S2Value = 2 } };
}
internal class Program
{
static void Main(string[] args)
{
//read from file, is file not exists, create one by new T object
var tans = SimpleXMLConfigureFileHelper.NET.SimpleXMLConfig.ReadConfigFile<TestClass>(@"./Settings.xml");
tans.TestString = "123456";
//write class to XML file, replace file if exists
SimpleXMLConfigureFileHelper.NET.SimpleXMLConfig.SaveConfigFile(tans, @"./Settings.xml", "2.0");
Console.ReadLine();
}
}
}
Created XML configure file
<?xml version="1.0" encoding="utf-8"?>
<root>
<ProgramSettings ProgramVersion="2.0" />
<Config vint="1" vint64="2" vint32="3" vint16="0" vbyte="255" vb="False" vdouble="0" vfloat="2.1" TestString="123456">
<Sub1 S1Value="0" />
<Sub2 S2Value="0">
<ints>
<String>sd1</String>
<String>sd2</String>
</ints>
</Sub2>
<Ints2>
<Int32>12</Int32>
<Int32>56</Int32>
<Int32>54</Int32>
</Ints2>
<sub2s />
<sub3s>
<Sub2 S2Value="1">
<ints>
<String>sd1</String>
<String>sd2</String>
</ints>
</Sub2>
<Sub2 S2Value="2">
<ints>
<String>sd1</String>
<String>sd2</String>
</ints>
</Sub2>
</sub3s>
</Config>
</root>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8.2
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.