Skip to content

Commit

Permalink
ExampleGenConfig 新增黑名单可选泛型列表 (#1083)
Browse files Browse the repository at this point in the history
* Update faq.md

补充 xlua.access, no field __Hitfix0_Update 错误的解决方案

* ExampleGenConfig 新增黑名单可选泛型列表

修复 XLua -> GenerateCode 的代码存在 The type 'Span<byte>' may not be used as a type argument 报错的问题

* Update faq.md

* Update ExampleGenConfig.cs

* Update ExampleGenConfig.cs
  • Loading branch information
dreamCirno authored Apr 19, 2024
1 parent 19ac20d commit 273c202
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Assets/XLua/Examples/ExampleGenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System;
using UnityEngine;
using XLua;
using System.Linq;
//using System.Reflection;
//using System.Linq;

//配置的详细介绍请看Doc下《XLua的配置.doc》
public static class ExampleGenConfig
Expand Down Expand Up @@ -96,4 +96,34 @@ public static class ExampleGenConfig
new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
};

public static List<Type> BlackGenericTypeList = new List<Type>()
{
typeof(Span<>),
typeof(ReadOnlySpan<>),
};

private static bool IsBlacklistedGenericType(Type type)
{
if (!type.IsGenericType) return false;
return BlackGenericTypeList.Contains(type.GetGenericTypeDefinition());
}

[BlackList] public static Func<MemberInfo, bool> GenericTypeFilter = (memberInfo) =>
{
switch (memberInfo)
{
case PropertyInfo propertyInfo:
return IsBlacklistedGenericType(propertyInfo.PropertyType);

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

case MethodInfo methodInfo:
return methodInfo.GetParameters().Any(p => IsBlacklistedGenericType(p.ParameterType));

default:
return false;
}
};
}

1 comment on commit 273c202

@JosephStar318
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in ExampleGenConfig.cs System.reflections left commented out. it gives error

Please sign in to comment.