Skip to content

Commit

Permalink
fix: 修复在 Unity 2022 下生成代码报 Span 无法作泛型参数的问题 (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull authored Dec 18, 2023
1 parent 0d68213 commit dc39f17
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Assets/XLua/Editor/XLuaUnityDefaultConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XLua;

/// <summary>
/// xLua 默认配置
/// </summary>
static class XLuaUnityDefaultConfig
{

#if UNITY_2022_1_OR_NEWER
static bool IsSpanType(Type type)
{
if (!type.IsGenericType)
return false;

var genericDefinition = type.GetGenericTypeDefinition();

return
genericDefinition == typeof(Span<>) ||
genericDefinition == typeof(ReadOnlySpan<>);
}

static bool IsSpanMember(MemberInfo memberInfo)
{
switch (memberInfo)
{
case FieldInfo fieldInfo:
return IsSpanType(fieldInfo.FieldType);

case PropertyInfo propertyInfo:
return IsSpanType(propertyInfo.PropertyType);

case ConstructorInfo constructorInfo:
return constructorInfo.GetParameters().Any(p => IsSpanType(p.ParameterType));

case MethodInfo methodInfo:
return methodInfo.GetParameters().Any(p => IsSpanType(p.ParameterType)) || IsSpanType(methodInfo.ReturnType);

default:
return false;
}
}

[BlackList]
public static Func<MemberInfo, bool> SpanMembersFilter = IsSpanMember;

#endif
}

0 comments on commit dc39f17

Please sign in to comment.