Skip to content

Commit

Permalink
Remove warning and remove redundant type lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
FejZa committed Feb 22, 2024
1 parent ffdaf52 commit cd1758b
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions Runtime/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using Debug = UnityEngine.Debug;

namespace RealityCollective.Extensions
Expand Down Expand Up @@ -130,39 +129,27 @@ public static bool TryResolveType(Guid guid, out Type resolvedType)
}

/// <summary>
/// Attempts to resolve the type using a the <see cref="System.Type.AssemblyQualifiedName"/> or <see cref="Type.GUID"/> as <see cref="string"/>.
/// Attempts to resolve the type using a the <see cref="Type.AssemblyQualifiedName"/> or <see cref="Type.GUID"/> as <see cref="string"/>.
/// </summary>
/// <param name="typeRef">The <see cref="Type.GUID"/> or <see cref="System.Type.AssemblyQualifiedName"/> as <see cref="string"/>.</param>
/// <param name="typeRef">The <see cref="Type.GUID"/> or <see cref="Type.AssemblyQualifiedName"/> as <see cref="string"/>.</param>
/// <param name="resolvedType">The resolved <see cref="Type"/>.</param>
/// <returns>True if the <see cref="resolvedType"/> was successfully obtained from or added to the <see cref="TypeCache"/>, otherwise false.</returns>
public static bool TryResolveType(string typeRef, out Type resolvedType)
{
resolvedType = null;

if (string.IsNullOrEmpty(typeRef)) { return false; }
if (string.IsNullOrEmpty(typeRef))
{
return false;
}

if (Guid.TryParse(typeRef, out var guid))
{
return TryResolveType(guid, out resolvedType);
}

resolvedType = Type.GetType(typeRef);

if (resolvedType != null)
{
if (resolvedType.GUID != Guid.Empty)
{
return TryResolveType(guid, out resolvedType);
}

if (!resolvedType.IsAbstract)
{
Debug.LogWarning($"{resolvedType.Name} is missing a {nameof(GuidAttribute)}. This extension has been upgraded to use System.Type.GUID instead of System.Type.AssemblyQualifiedName");
return true;
}
}

return false;
return resolvedType != null && !resolvedType.IsAbstract;
}

/// <summary>
Expand Down

0 comments on commit cd1758b

Please sign in to comment.