forked from Tencent/xLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复在 Unity 2022 下生成代码报 Span 无法作泛型参数的问题 (Tencent#1104)
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
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 | ||
} |