Skip to content

Commit

Permalink
[unity]获取一个扩展函数所扩展的类时,不符合标准的返回null,不报错,fix #1893
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Nov 4, 2024
1 parent 9c6534c commit c999635
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/TypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,28 @@ public static class ExtensionMethodInfo
{
private static Type GetExtendedType(MethodInfo method)
{
var paramInfo = method.GetParameters();
if (paramInfo.Length == 0)
{
return null;
}
if (method.GetCustomAttribute<ExtensionAttribute>() == null)
{
return null;
}
var type = method.GetParameters()[0].ParameterType;
if (!type.IsGenericParameter)
return type;
var parameterConstraints = type.GetGenericParameterConstraints();
if (parameterConstraints.Length == 0)
throw new InvalidOperationException();
if (parameterConstraints.Length == 0)
{
return null;
}
var firstParameterConstraint = parameterConstraints[0];
if (!firstParameterConstraint.IsClass)
throw new InvalidOperationException();
if (!firstParameterConstraint.IsClass)
{
return null;
}
return firstParameterConstraint;
}

Expand Down

0 comments on commit c999635

Please sign in to comment.