using System; using Godot.Collections; using Array = Godot.Collections.Array; namespace Godot.SourceGenerators.Sample; public class MustBeVariantMethods { public void MustBeVariantMethodCalls() { Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); Method(); // This call fails because generic type is not Variant-compatible. //Method(); } public void Method<[MustBeVariant] T>() { } public void MustBeVariantClasses() { new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); new ClassWithGenericVariant(); // This class fails because generic type is not Variant-compatible. //new ClassWithGenericVariant(); } } public class ClassWithGenericVariant<[MustBeVariant] T> { } public class MustBeVariantAnnotatedMethods { [GenericTypeAttribute()] public void MethodWithAttributeOk() { } // This method definition fails because generic type is not Variant-compatible. /* [GenericTypeAttribute()] public void MethodWithWrongAttribute() { } */ } [GenericTypeAttribute()] public class ClassVariantAnnotated { } // This class definition fails because generic type is not Variant-compatible. /* [GenericTypeAttribute()] public class ClassNonVariantAnnotated { } */ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public class GenericTypeAttribute<[MustBeVariant] T> : Attribute { }