Skip to content

Commit

Permalink
Changed Dump overload to be generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Emik03 committed Jul 16, 2021
1 parent ecbb405 commit 915da23
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Documentation/KeepCoding_IDump.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Derived

| Methods | |
| :--- | :--- |
| [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/> |
| [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/> |
| [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/> |
| [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 number Diff line number Diff line change
@@ -1,16 +1,20 @@
#### [KeepCoding](index.md 'index')
### [KeepCoding](KeepCoding.md 'KeepCoding').[IDump](KeepCoding_IDump.md 'KeepCoding.IDump')
## IDump.Dump(object, bool) Method
## IDump.Dump&lt;T&gt;(T, bool) Method
Dumps all information that it can find of the type using reflection. This should only be used to debug.
```csharp
void Dump(object obj, bool getVariables=false);
void Dump<T>(T obj, bool getVariables=false);
```
#### Type parameters
<a name='KeepCoding_IDump_Dump_T_(T_bool)_T'></a>
`T`

#### Parameters
<a name='KeepCoding_IDump_Dump(object_bool)_obj'></a>
`obj` [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object')
<a name='KeepCoding_IDump_Dump_T_(T_bool)_obj'></a>
`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')
The object to reflect on.

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

2 changes: 1 addition & 1 deletion Documentation/KeepCoding_Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Implements [IDump](KeepCoding_IDump.md 'KeepCoding.IDump'), [ILog](KeepCoding_IL

| Methods | |
| :--- | :--- |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [Equals(object)](KeepCoding_Logger_Equals(object).md 'KeepCoding.Logger.Equals(object)') | Determines if both objects are equal.<br/> |
| [GetHashCode()](KeepCoding_Logger_GetHashCode().md 'KeepCoding.Logger.GetHashCode()') | Gets the hash code of the object.<br/> |
Expand Down
18 changes: 0 additions & 18 deletions Documentation/KeepCoding_Logger_Dump(object_bool).md

This file was deleted.

23 changes: 23 additions & 0 deletions Documentation/KeepCoding_Logger_Dump_T_(T_bool).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#### [KeepCoding](index.md 'index')
### [KeepCoding](KeepCoding.md 'KeepCoding').[Logger](KeepCoding_Logger.md 'KeepCoding.Logger')
## Logger.Dump&lt;T&gt;(T, bool) Method
Dumps all information that it can find of the type using reflection. This should only be used to debug.
```csharp
public void Dump<T>(T obj, bool getVariables=false);
```
#### Type parameters
<a name='KeepCoding_Logger_Dump_T_(T_bool)_T'></a>
`T`
The type of component to reflect on.

#### Parameters
<a name='KeepCoding_Logger_Dump_T_(T_bool)_obj'></a>
`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')
The object to reflect on.

<a name='KeepCoding_Logger_Dump_T_(T_bool)_getVariables'></a>
`getVariables` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
Whether it should search recursively for the elements within the elements.


Implements [Dump<T>(T, bool)](KeepCoding_IDump_Dump_T_(T_bool).md 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool)')
2 changes: 1 addition & 1 deletion Documentation/KeepCoding_ModuleScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Implements [IDump](KeepCoding_IDump.md 'KeepCoding.IDump'), [ILog](KeepCoding_IL
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
| [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/> |
Expand Down
18 changes: 0 additions & 18 deletions Documentation/KeepCoding_ModuleScript_Dump(object_bool).md

This file was deleted.

22 changes: 22 additions & 0 deletions Documentation/KeepCoding_ModuleScript_Dump_T_(T_bool).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#### [KeepCoding](index.md 'index')
### [KeepCoding](KeepCoding.md 'KeepCoding').[ModuleScript](KeepCoding_ModuleScript.md 'KeepCoding.ModuleScript')
## ModuleScript.Dump&lt;T&gt;(T, bool) Method
Dumps all information that it can find of the type using reflection. This should only be used to debug.
```csharp
public void Dump<T>(T obj, bool getVariables=false);
```
#### Type parameters
<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_T'></a>
`T`

#### Parameters
<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_obj'></a>
`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')
The object to reflect on.

<a name='KeepCoding_ModuleScript_Dump_T_(T_bool)_getVariables'></a>
`getVariables` [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean')
Whether it should search recursively for the elements within the elements.


Implements [Dump<T>(T, bool)](KeepCoding_IDump_Dump_T_(T_bool).md 'KeepCoding.IDump.Dump&lt;T&gt;(T, bool)')
18 changes: 9 additions & 9 deletions Source/Instances/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,28 @@ public Logger(string name, bool showId = false, bool showInLfa = true)
/// <summary>
/// Dumps all information that it can find of the type using reflection. This should only be used to debug.
/// </summary>
/// <typeparam name="T">The type of component to reflect on.</typeparam>
/// <param name="obj">The object to reflect on.</param>
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
public void Dump(object obj, bool getVariables = false)
public void Dump<T>(T obj, bool getVariables = false)
{
int index = 0;

string Format<T>(string name, T value) => VariableTemplate.Form(index++, name, value?.GetType().ToString() ?? Null, Join(", ", value.Unwrap(getVariables).Select(o => o.ToString()).ToArray()));
string Format<TValue>(in string name, ref int index, in TValue value) => VariableTemplate.Form(index++, name, typeof(TValue).ToString() ?? Null, value.UnwrapToString(getVariables));

var values = new List<object>();
int index = 0;
var values = new List<string>();

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

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

/// <summary>
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.
/// </summary>
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
/// <param name="logs">All of the variables to throughly log.</param>
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);
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);

/// <summary>
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.
Expand Down
2 changes: 1 addition & 1 deletion Source/Interfaces/IDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IDump
/// </summary>
/// <param name="obj">The object to reflect on.</param>
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
public void Dump(object obj, bool getVariables = false);
public void Dump<T>(T obj, bool getVariables = false);

/// <summary>
/// Dumps all information about the variables specified. Each element uses the syntax () => varName. This should only be used to debug.
Expand Down
2 changes: 1 addition & 1 deletion Source/MonoBehaviours/ModuleScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void ButtonEffect(KMSelectable selectable, float intensityModifier = 0, p
/// </summary>
/// <param name="obj">The object to reflect on.</param>
/// <param name="getVariables">Whether it should search recursively for the elements within the elements.</param>
public void Dump(object obj, bool getVariables = false) => _logger.Dump(obj, getVariables);
public void Dump<T>(T obj, bool getVariables = false) => _logger.Dump(obj, getVariables);

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

0 comments on commit 915da23

Please sign in to comment.