当接口类型被标记时,所有实现该接口的类型也将被标记。
using System; using UnityEngine; using UnityEngine.Scripting;
public class NewBehaviourScript : MonoBehaviour { void Start() { IFoo ifoo = new Foo(); } }
[RequireImplementors] interface IFoo {}
class Foo : IFoo {}
// UnusedFoo is not used, however, it will survive managed code stripping due to IFoo having the [RequireImplementors] attribute. class UnusedFoo : IFoo { // Note that unused members of UnusedFoo will still be removed by managed code stripping public static void UnusedMethod() {} }
// IBar is not used so it will be removed by managed code stripping [RequireImplementors] interface IBar {}
// Because IBar is not used, the [RequireImplementors] attribute on IBar has no impact. UnusedBar will also be removed. class UnusedBar : IBar {}