-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from GetStream/feature/uni-64-add-debug-info-…
…around-mediastream Feature/uni 64 add debug info around mediastream
- Loading branch information
Showing
5 changed files
with
164 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Packages/StreamVideo/Runtime/Core/Utils/DebugObjectPrinter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace StreamVideo.Core.Utils | ||
{ | ||
#if STREAM_DEBUG_ENABLED | ||
internal class DebugObjectPrinter | ||
{ | ||
public static string PrintObject(object obj, int maxDepth = 10) | ||
=> PrintObjectInternal(obj, new HashSet<object>(), 0, maxDepth); | ||
|
||
private static string PrintObjectInternal(object obj, HashSet<object> visited, int depth, int maxDepth) | ||
{ | ||
if (obj == null) | ||
return "null"; | ||
|
||
if (depth >= maxDepth) | ||
return $"[Max depth {maxDepth} reached]"; | ||
|
||
// Handle primitive types and strings | ||
if (obj.GetType().IsPrimitive || obj is string || obj is DateTime) | ||
return obj.ToString(); | ||
|
||
// Prevent circular references | ||
if (!obj.GetType().IsValueType) | ||
{ | ||
if (visited.Contains(obj)) | ||
return "[Circular Reference]"; | ||
visited.Add(obj); | ||
} | ||
|
||
var sb = new StringBuilder(); | ||
var type = obj.GetType(); | ||
|
||
// Handle collections | ||
if (obj is IEnumerable enumerable && !(obj is string)) | ||
{ | ||
sb.Append($"{type.Name} ["); | ||
bool first = true; | ||
foreach (var item in enumerable) | ||
{ | ||
if (!first) sb.Append(", "); | ||
sb.Append(PrintObjectInternal(item, visited, depth + 1, maxDepth)); | ||
first = false; | ||
} | ||
|
||
sb.Append("]"); | ||
return sb.ToString(); | ||
} | ||
|
||
// Handle objects | ||
sb.AppendLine($"{type.Name} {{"); | ||
|
||
// Get all fields (both public and private) | ||
var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | | ||
BindingFlags.Instance | BindingFlags.Static); | ||
foreach (var field in fields) | ||
{ | ||
var value = field.GetValue(obj); | ||
sb.AppendLine($" {field.Name} ({field.Attributes}): " + | ||
PrintObjectInternal(value, visited, depth + 1, maxDepth)); | ||
} | ||
|
||
// Get all properties | ||
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | | ||
BindingFlags.Instance | BindingFlags.Static); | ||
|
||
foreach (var prop in properties) | ||
{ | ||
try | ||
{ | ||
var value = prop.GetValue(obj, null); | ||
sb.AppendLine($" {prop.Name} ({prop.Attributes}): " + | ||
PrintObjectInternal(value, visited, depth + 1, maxDepth)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
sb.AppendLine($" {prop.Name}: [Error accessing property: {ex.Message}]"); | ||
} | ||
} | ||
|
||
sb.Append("}"); | ||
return sb.ToString(); | ||
} | ||
} | ||
#endif | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/StreamVideo/Runtime/Core/Utils/DebugObjectPrinter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.