com.wallstop-studios.unity-helpers 2.0.0-rc10 → 2.0.0-rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,10 +6,9 @@ namespace UnityHelpers.Core.Extension
|
|
|
6
6
|
{
|
|
7
7
|
using System;
|
|
8
8
|
using System.Collections.Generic;
|
|
9
|
-
using System.
|
|
9
|
+
using System.Reflection;
|
|
10
10
|
using System.Runtime.CompilerServices;
|
|
11
11
|
using System.Threading;
|
|
12
|
-
using Helper;
|
|
13
12
|
using JetBrains.Annotations;
|
|
14
13
|
using UnityEngine;
|
|
15
14
|
using Utils;
|
|
@@ -25,6 +24,8 @@ namespace UnityHelpers.Core.Extension
|
|
|
25
24
|
private static long _cacheAccessCount;
|
|
26
25
|
|
|
27
26
|
private static readonly HashSet<Object> Disabled = new();
|
|
27
|
+
private static readonly Dictionary<Type, FieldInfo[]> FieldCache = new();
|
|
28
|
+
private static readonly Dictionary<Type, PropertyInfo[]> PropertyCache = new();
|
|
28
29
|
|
|
29
30
|
static LoggingExtensions()
|
|
30
31
|
{
|
|
@@ -60,6 +61,45 @@ namespace UnityHelpers.Core.Extension
|
|
|
60
61
|
Disabled.Add(component);
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
public static string GenericToString(this Object component)
|
|
65
|
+
{
|
|
66
|
+
if (component == null)
|
|
67
|
+
{
|
|
68
|
+
return "null";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Dictionary<string, object> structure = new();
|
|
72
|
+
Type type = component.GetType();
|
|
73
|
+
FieldInfo[] fields = FieldCache.GetOrAdd(
|
|
74
|
+
type,
|
|
75
|
+
inType => inType.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
|
76
|
+
);
|
|
77
|
+
PropertyInfo[] properties = PropertyCache.GetOrAdd(
|
|
78
|
+
type,
|
|
79
|
+
inType => inType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
|
80
|
+
);
|
|
81
|
+
foreach (FieldInfo field in fields)
|
|
82
|
+
{
|
|
83
|
+
structure[field.Name] = ValueFormat(field.GetValue(component));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
foreach (PropertyInfo property in properties)
|
|
87
|
+
{
|
|
88
|
+
structure[property.Name] = ValueFormat(property.GetValue(component));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return structure.ToJson();
|
|
92
|
+
|
|
93
|
+
object ValueFormat(object value)
|
|
94
|
+
{
|
|
95
|
+
if (value is Object obj && obj != null)
|
|
96
|
+
{
|
|
97
|
+
return obj.name;
|
|
98
|
+
}
|
|
99
|
+
return value?.ToString();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
63
103
|
[StringFormatMethod("message")]
|
|
64
104
|
public static void Log(this Object component, string message, params object[] args)
|
|
65
105
|
{
|