mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
add summary to AutoToString
This commit is contained in:
parent
757283f4e7
commit
be39dcf8d8
@ -40,17 +40,18 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AutoToString
|
#region AutoToString
|
||||||
|
/// <summary> slow but automatic conversion of ValueType to string in the format "name(field1, field2... fieldn)" </summary>
|
||||||
public static string AutoToString<T>(this T self, bool isWriteName = true) where T : struct
|
public static string AutoToString<T>(this T self, bool isWriteName = true) where T : struct
|
||||||
{
|
{
|
||||||
return AutoToString(self, typeof(T), isWriteName);
|
return AutoToString(self, typeof(T), isWriteName);
|
||||||
}
|
}
|
||||||
private static string AutoToString(object target, Type type, bool isWriteName)
|
private static string AutoToString(object target, Type type, bool isWriteName)
|
||||||
{
|
{
|
||||||
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
string[] values = new string[fields.Length];
|
string[] values = new string[fields.Length];
|
||||||
for (int i = 0; i < fields.Length; i++)
|
for (int i = 0; i < fields.Length; i++)
|
||||||
values[i] = fields[i].GetValue(target).ToString();
|
values[i] = fields[i].GetValue(target).ToString();
|
||||||
if(isWriteName)
|
if (isWriteName)
|
||||||
return $"{type.Name}({string.Join(", ", values)})";
|
return $"{type.Name}({string.Join(", ", values)})";
|
||||||
else
|
else
|
||||||
return $"({string.Join(", ", values)})";
|
return $"({string.Join(", ", values)})";
|
||||||
|
Loading…
Reference in New Issue
Block a user