Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过GetCustomAttributes获取Attribute,ILRuntime与预期结果不一致 #725

Open
526077247 opened this issue Aug 7, 2022 · 2 comments

Comments

@526077247
Copy link

526077247 commented Aug 7, 2022

Describe the bug
通过GetCustomAttributes获取Attribute,ILRuntime与预期结果不一致

To Reproduce

    [AttributeUsage(AttributeTargets.Class,AllowMultiple = true)]
    public class TestSystemAttribute:Attribute
    {
        public List<int> KeyCode { get; }


        public TestSystemAttribute(int[] keyCode)
        {
            this.KeyCode = new List<int>(keyCode) ;
        }
    }
    [AttributeUsage(AttributeTargets.Class,AllowMultiple = true)]
    public class TestSystem2Attribute:Attribute
    {
        public int[] KeyCode { get; }


        public TestSystem2Attribute(int[] keyCode)
        {
            this.KeyCode = keyCode;
        }
    }
    [TestSystem2(new []{1,2})]
    [TestSystem(new []{1,2})]
    public class Test
    {
        
    }

    public class AttributeTest
    {
        public static void TestRun()
        {
            var attrs = typeof (Test).GetCustomAttributes(typeof (TestSystemAttribute), false);

            Console.WriteLine(attrs.Length);// attrs.Length=0,此处该为1才对
            
            var attr2s= typeof (Test).GetCustomAttributes(typeof (TestSystem2Attribute), false);
            foreach (TestSystem2Attribute attr in attr2s)
            {
                Console.WriteLine(attr.KeyCode[0]);//IL_0078: ldelem.i4  
            }
        }
    }

Expected behavior
执行TestRun

Unity Version
2020.3.33f1

ILRuntime Version
075a480

@BoysheO
Copy link

BoysheO commented Aug 15, 2022

你IL2CPP用GetCustomAttributes不报错吗

@526077247
Copy link
Author

ILRuntime域里使用,不在主工程

@526077247 526077247 changed the title 通过GetCustomAttributes获取Attribute,ILRuntime与AOT结果不一致 通过GetCustomAttributes获取Attribute,ILRuntime与预期结果不一致 Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants