Ourpalm / ILRuntime

Pure C# IL Intepreter Runtime, which is fast and reliable for scripting requirement on enviorments, where jitting isn't possible.
Other
2.99k stars 656 forks source link

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

Open 526077247 opened 2 years ago

526077247 commented 2 years ago

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 075a4805251f6c5bbe59f6398d7e4ac9160fdd16

BoysheO commented 2 years ago

你IL2CPP用GetCustomAttributes不报错吗

526077247 commented 2 years ago

ILRuntime域里使用,不在主工程