mirror of
https://git.lewd.wtf/PGR/ascnet
synced 2025-12-13 21:04:37 +01:00
config.tab
This commit is contained in:
37
AscNet.Common/Util/TsvTool.cs
Normal file
37
AscNet.Common/Util/TsvTool.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace AscNet.Common.Util
|
||||
{
|
||||
public static class TsvTool
|
||||
{
|
||||
public static string SerializeObject<T>(IEnumerable<T> objs) where T : new()
|
||||
{
|
||||
string res = string.Empty;
|
||||
|
||||
Type type = typeof(T);
|
||||
var properties = type.GetProperties()
|
||||
.OrderBy(p => p.GetCustomAttribute<PropertyOrderAttribute>()?.Order ?? int.MaxValue)
|
||||
.ToList();
|
||||
|
||||
res += string.Join('\t', properties.Select(x => x.Name)) + '\n';
|
||||
|
||||
foreach (var obj in objs)
|
||||
{
|
||||
res += string.Join('\t', properties.Select(x => x.GetValue(obj))) + '\n';
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class PropertyOrderAttribute : Attribute
|
||||
{
|
||||
public int Order { get; }
|
||||
|
||||
public PropertyOrderAttribute(int order)
|
||||
{
|
||||
Order = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user