谁能告诉我为什么customType.getFields(BindingFlags.NonPublic)会检测到公共事件|我甚至创建了自定义的空属性,这些属性应该作为包含哪些字段的标志,但它仍然不起作用。当我执行GetCustomAttribute()时,它显示为null,即使我将属性放在那里
var Fields = customType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance).
Where(field => field.GetCustomAttribute( typeof(PrivateIgnore) ) == null ).ToArray();
这是自定义类
public class Health : Property
{
int _maxMealth;
[PrivateIgnore] int _healthAmount;
[PrivateIgnore] public event Action<GameEntity> TakesDamage;//i added the attribute just in case (even though it shouldn't be detected because it's public)
[PrivateIgnore] public event Action<GameEntity> Dies;
public int HealthAmount => _healthAmount;//this isn't detected
//when i tested, public int fields are not detected as well
}
这是我的自定义属性
public class PrivateIgnore : Attribute {}
1条答案
按热度按时间vlju58qv1#
该事件被分成不同的字段,这些字段都有[CompileGenerated]属性。因此,要忽略事件和其他数据类型,必须包括对该属性的检查: