Game.Reflection.EnumArrayAttribute
Assembly: Assembly-CSharp.dll
Namespace: Game.Reflection
Type: class
Base: System.Attribute
Summary:
Attribute used to mark a method, property or field as representing an array whose elements correspond to the values of a specific enum type. Stores the enum Type so tools, serializers or editors can validate or present the array according to the enum (for example ensuring array length matches the enum value count or mapping indices to enum names).
Fields
None
This type declares no backing fields.
Properties
public Type type { get; set; }
The enum Type that the annotated array corresponds to. Consumers can use this to determine the enum's values (e.g., Enum.GetValues(type).Length) or to map array indices to enum names.
Constructors
public EnumArrayAttribute(Type type)
Creates a new attribute instance and sets the target enum Type. The provided Type is expected to be an enum Type.
Methods
None
This attribute type does not define methods beyond the constructor and the auto-property accessors.
Usage Example
using Game.Reflection;
using System;
public enum ZoneType
{
Residential,
Commercial,
Industrial,
Park
}
public class ExampleComponent
{
// Annotate an array so tools know it maps to ZoneType values
[EnumArrayAttribute(typeof(ZoneType))]
public int[] zoneCapacities = new int[Enum.GetValues(typeof(ZoneType)).Length];
}
Notes: - The attribute is declared with [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field)], so it can be applied to methods, properties and fields. - Consumers should validate that the provided Type is actually an enum before using it (e.g., Type.IsEnum).