Skip to content

Commit 915da23

Browse files
committed
Changed Dump overload to be generic
1 parent ecbb405 commit 915da23

11 files changed

+68
-55
lines changed

Documentation/KeepCoding_IDump.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Derived
1212

1313
| Methods | |
1414
| :--- | :--- |
15+
| [Dump&lt;T&gt;(T, bool)](KeepCoding_IDump_Dump_T_(T_bool).md 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
1516
| [Dump(bool, Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_IDump_Dump(bool_System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.IDump.Dump(bool, System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
16-
| [Dump(object, bool)](KeepCoding_IDump_Dump(object_bool).md 'KeepCoding.IDump.Dump(object, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
1717
| [Dump(Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_IDump_Dump(System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.IDump.Dump(System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#### [KeepCoding](index.md 'index')
22
### [KeepCoding](KeepCoding.md 'KeepCoding').[IDump](KeepCoding_IDump.md 'KeepCoding.IDump')
3-
## IDump.Dump(object, bool) Method
3+
## IDump.Dump&lt;T&gt;(T, bool) Method
44
Dumps all information that it can find of the type using reflection. This should only be used to debug.
55
```csharp
6-
void Dump(object obj, bool getVariables=false);
6+
void Dump<T>(T obj, bool getVariables=false);
77
```
8+
#### Type parameters
9+
<a name='KeepCoding_IDump_Dump_T_(T_bool)_T'></a>
10+
`T`
11+
812
#### Parameters
9-
<a name='KeepCoding_IDump_Dump(object_bool)_obj'></a>
10-
`obj` [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object')
13+
<a name='KeepCoding_IDump_Dump_T_(T_bool)_obj'></a>
14+
`obj` [T](KeepCoding_IDump_Dump_T_(T_bool).md#KeepCoding_IDump_Dump_T_(T_bool)_T 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool).T')
1115
The object to reflect on.
1216

13-
<a name='KeepCoding_IDump_Dump(object_bool)_getVariables'></a>
17+
<a name='KeepCoding_IDump_Dump_T_(T_bool)_getVariables'></a>
1418
`getVariables` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
1519
Whether it should search recursively for the elements within the elements.
1620

Documentation/KeepCoding_Logger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Implements [IDump](KeepCoding_IDump.md 'KeepCoding.IDump'), [ILog](KeepCoding_IL
2424

2525
| Methods | |
2626
| :--- | :--- |
27+
| [Dump&lt;T&gt;(T, bool)](KeepCoding_Logger_Dump_T_(T_bool).md 'KeepCoding.Logger.Dump&lt;T&gt;(T, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
2728
| [Dump(bool, Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_Logger_Dump(bool_System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.Logger.Dump(bool, System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
28-
| [Dump(object, bool)](KeepCoding_Logger_Dump(object_bool).md 'KeepCoding.Logger.Dump(object, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
2929
| [Dump(Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_Logger_Dump(System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.Logger.Dump(System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
3030
| [Equals(object)](KeepCoding_Logger_Equals(object).md 'KeepCoding.Logger.Equals(object)') | Determines if both objects are equal.<br/> |
3131
| [GetHashCode()](KeepCoding_Logger_GetHashCode().md 'KeepCoding.Logger.GetHashCode()') | Gets the hash code of the object.<br/> |

Documentation/KeepCoding_Logger_Dump(object_bool).md

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### [KeepCoding](index.md 'index')
2+
### [KeepCoding](KeepCoding.md 'KeepCoding').[Logger](KeepCoding_Logger.md 'KeepCoding.Logger')
3+
## Logger.Dump&lt;T&gt;(T, bool) Method
4+
Dumps all information that it can find of the type using reflection. This should only be used to debug.
5+
```csharp
6+
public void Dump<T>(T obj, bool getVariables=false);
7+
```
8+
#### Type parameters
9+
<a name='KeepCoding_Logger_Dump_T_(T_bool)_T'></a>
10+
`T`
11+
The type of component to reflect on.
12+
13+
#### Parameters
14+
<a name='KeepCoding_Logger_Dump_T_(T_bool)_obj'></a>
15+
`obj` [T](KeepCoding_Logger_Dump_T_(T_bool).md#KeepCoding_Logger_Dump_T_(T_bool)_T 'KeepCoding.Logger.Dump&lt;T&gt;(T, bool).T')
16+
The object to reflect on.
17+
18+
<a name='KeepCoding_Logger_Dump_T_(T_bool)_getVariables'></a>
19+
`getVariables` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
20+
Whether it should search recursively for the elements within the elements.
21+
22+
23+
Implements [Dump<T>(T, bool)](KeepCoding_IDump_Dump_T_(T_bool).md 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool)')

Documentation/KeepCoding_ModuleScript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Implements [IDump](KeepCoding_IDump.md 'KeepCoding.IDump'), [ILog](KeepCoding_IL
3737
| [Assign(Action, Action, Action, Action, Action, Action)](KeepCoding_ModuleScript_Assign(System_Action_System_Action_System_Action_System_Action_System_Action_System_Action).md 'KeepCoding.ModuleScript.Assign(System.Action, System.Action, System.Action, System.Action, System.Action, System.Action)') | Assigns events specified into [Module](KeepCoding_ModuleScript_Module.md 'KeepCoding.ModuleScript.Module'). Reassigning them will replace their values.<br/> |
3838
| [Awake()](KeepCoding_ModuleScript_Awake().md 'KeepCoding.ModuleScript.Awake()') | This initalizes the module. If you have an Awake method, be sure to call `base.Awake()` as the first statement.<br/> |
3939
| [ButtonEffect(KMSelectable, float, Sound[])](KeepCoding_ModuleScript_ButtonEffect(KMSelectable_float_KeepCoding_Sound__).md 'KeepCoding.ModuleScript.ButtonEffect(KMSelectable, float, KeepCoding.Sound[])') | Handles typical button [KMSelectable.OnInteract](https://docs.microsoft.com/en-us/dotnet/api/KMSelectable.OnInteract 'KMSelectable.OnInteract') behaviour.<br/> |
40+
| [Dump&lt;T&gt;(T, bool)](KeepCoding_ModuleScript_Dump_T_(T_bool).md 'KeepCoding.ModuleScript.Dump&lt;T&gt;(T, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
4041
| [Dump(bool, Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_ModuleScript_Dump(bool_System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.ModuleScript.Dump(bool, System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
41-
| [Dump(object, bool)](KeepCoding_ModuleScript_Dump(object_bool).md 'KeepCoding.ModuleScript.Dump(object, bool)') | Dumps all information that it can find of the type using reflection. This should only be used to debug.<br/> |
4242
| [Dump(Expression&lt;Func&lt;object&gt;&gt;[])](KeepCoding_ModuleScript_Dump(System_Linq_Expressions_Expression_System_Func_object____).md 'KeepCoding.ModuleScript.Dump(System.Linq.Expressions.Expression&lt;System.Func&lt;object&gt;&gt;[])') | Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.<br/> |
4343
| [Log&lt;T&gt;(T, LogType)](KeepCoding_ModuleScript_Log_T_(T_LogType).md 'KeepCoding.ModuleScript.Log&lt;T&gt;(T, LogType)') | Logs message, but formats it to be compliant with the Logfile Analyzer.<br/> |
4444
| [Log&lt;T&gt;(T, object[])](KeepCoding_ModuleScript_Log_T_(T_object__).md 'KeepCoding.ModuleScript.Log&lt;T&gt;(T, object[])') | Logs multiple entries, but formats it to be compliant with the Logfile Analyzer.<br/> |

Documentation/KeepCoding_ModuleScript_Dump(object_bool).md

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#### [KeepCoding](index.md 'index')
2+
### [KeepCoding](KeepCoding.md 'KeepCoding').[ModuleScript](KeepCoding_ModuleScript.md 'KeepCoding.ModuleScript')
3+
## ModuleScript.Dump&lt;T&gt;(T, bool) Method
4+
Dumps all information that it can find of the type using reflection. This should only be used to debug.
5+
```csharp
6+
public void Dump<T>(T obj, bool getVariables=false);
7+
```
8+
#### Type parameters
9+
<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_T'></a>
10+
`T`
11+
12+
#### Parameters
13+
<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_obj'></a>
14+
`obj` [T](KeepCoding_ModuleScript_Dump_T_(T_bool).md#KeepCoding_ModuleScript_Dump_T_(T_bool)_T 'KeepCoding.ModuleScript.Dump&lt;T&gt;(T, bool).T')
15+
The object to reflect on.
16+
17+
<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_getVariables'></a>
18+
`getVariables` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
19+
Whether it should search recursively for the elements within the elements.
20+
21+
22+
Implements [Dump<T>(T, bool)](KeepCoding_IDump_Dump_T_(T_bool).md 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool)')

Source/Instances/Logger.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,28 @@ public Logger(Type type, bool showId = false, bool showInLfa = true) : this(type
6666
/// <summary>
6767
/// Dumps all information that it can find of the type using reflection. This should only be used to debug.
6868
/// </summary>
69+
/// <typeparam name="T">The type of component to reflect on.</typeparam>
6970
/// <param name="obj">The object to reflect on.</param>
7071
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
71-
public void Dump(object obj, bool getVariables = false)
72+
public void Dump<T>(T obj, bool getVariables = false)
7273
{
73-
int index = 0;
74-
75-
string Format<T>(string name, T value) => VariableTemplate.Form(index++, name, value?.GetType().ToString() ?? Null, Join(", ", value.Unwrap(getVariables).Select(o => o.ToString()).ToArray()));
74+
string Format<TValue>(in string name, ref int index, in TValue value) => VariableTemplate.Form(index++, name, typeof(TValue).ToString() ?? Null, value.UnwrapToString(getVariables));
7675

77-
var values = new List<object>();
76+
int index = 0;
77+
var values = new List<string>();
7878

79-
obj.GetType().GetFields(Flags).ForEach(f => values.Add(Format(f.Name, f.GetValue(obj))));
80-
obj.GetType().GetProperties(Flags).ForEach(p => values.Add(Format(p.Name, p.GetValue(obj, null))));
79+
typeof(T).GetFields(Flags).ForEach(f => values.Add(Format(f.Name, ref index, f.GetValue(obj))));
80+
typeof(T).GetProperties(Flags).ForEach(p => values.Add(Format(p.Name, ref index, p.GetValue(obj, null))));
8181

82-
Log(Join("", values.Select(v => Join("", v.Unwrap(getVariables).Select(o => o.ToString()).ToArray())).ToArray()), LogType.Warning);
82+
Log(Join("", values.ToArray()), LogType.Warning);
8383
}
8484

8585
/// <summary>
8686
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.
8787
/// </summary>
8888
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
8989
/// <param name="logs">All of the variables to throughly log.</param>
90-
public void Dump(bool getVariables, params Expression<Func<object>>[] logs) => Log(Join("", logs.Select((l, n) => VariableTemplate.Form(n, l.NameOf(), l.Compile()()?.GetType().ToString() ?? Null, Join(", ", l.Compile()().Unwrap(getVariables).Select(o => o.ToString()).ToArray()))).ToArray()), LogType.Warning);
90+
public void Dump(bool getVariables, params Expression<Func<object>>[] logs) => Log(Join("", logs.Select((l, n) => VariableTemplate.Form(n, l.NameOf(), l.Compile()()?.GetType().ToString() ?? Null, l.Compile()().UnwrapToString())).ToArray()), LogType.Warning);
9191

9292
/// <summary>
9393
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.

Source/Interfaces/IDump.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IDump
1313
/// </summary>
1414
/// <param name="obj">The object to reflect on.</param>
1515
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
16-
public void Dump(object obj, bool getVariables = false);
16+
public void Dump<T>(T obj, bool getVariables = false);
1717

1818
/// <summary>
1919
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.

Source/MonoBehaviours/ModuleScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void ButtonEffect(KMSelectable selectable, float intensityModifier = 0, p
207207
/// </summary>
208208
/// <param name="obj">The object to reflect on.</param>
209209
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
210-
public void Dump(object obj, bool getVariables = false) => _logger.Dump(obj, getVariables);
210+
public void Dump<T>(T obj, bool getVariables = false) => _logger.Dump(obj, getVariables);
211211

212212
/// <summary>
213213
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.

0 commit comments

Comments
 (0)