xLua icon indicating copy to clipboard operation
xLua copied to clipboard

unity 2021.2 之后版本生成代码异常

Open fgh23387736 opened this issue 3 years ago • 9 comments

unity在2021.2之后使用了C#9,Api Compatibility Level 已经没有了.Net4.x,只能选择.Net Framework。在这个版本下生成代码会出现错误。跪求兼容 error CS0306: The type 'Span<byte>' may not be used as a type argument

fgh23387736 avatar Feb 22 '22 03:02 fgh23387736

image 我们这边加一句这个暂时规避了一下,等官方修复吧

Jidayong avatar Feb 24 '22 08:02 Jidayong

@Jidayong 谢谢

fgh23387736 avatar Feb 24 '22 09:02 fgh23387736

TimeSpan和DateTime类的生成代码也报类似的错

suoluosl avatar Feb 28 '22 08:02 suoluosl

能提供下完整的代码吗?🙏

AhrenLi avatar Apr 19 '22 02:04 AhrenLi

Unity2021.3.21f1 生成报错 image

image

leolichenxi avatar Nov 07 '22 06:11 leolichenxi

@Jidayong 加的那一行后还会有 image

image

leolichenxi avatar Nov 07 '22 06:11 leolichenxi

目前加入黑名单列表把报错的函数

leolichenxi avatar Nov 08 '22 06:11 leolichenxi

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;
    }
};

dreamCirno avatar Aug 18 '23 08:08 dreamCirno