Files
RobustToolbox/Robust.Shared/Serialization/Manager/Attributes/DataFieldAttribute.cs
T
c73b54862e Add analyzers to detect some prototype misuse (#6048)
* Add analyzers to detect some prototype misuse

Detects people marking prototype as NetSerializable.

Detects people creating new prototype instances themselves.

* Update Robust.Analyzers/PrototypeNetSerializableAnalyzer.cs

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
2025-06-26 22:24:23 +02:00

58 lines
1.9 KiB
C#

using System;
#if !ROBUST_ANALYZERS_TEST
using JetBrains.Annotations;
#endif
namespace Robust.Shared.Serialization.Manager.Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
#if !ROBUST_ANALYZERS_TEST
[MeansImplicitAssignment]
[MeansImplicitUse(ImplicitUseKindFlags.Assign)]
[Virtual]
#endif
public class DataFieldAttribute : DataFieldBaseAttribute
{
/// <summary>
/// The name of this field in YAML.
/// If null, the name of the C# field will be used instead, with the first letter lowercased.
/// </summary>
public string? Tag { get; internal set; }
/// <summary>
/// Whether or not this field being mapped is required for the component to function.
/// This will not guarantee that the field is mapped when the program is run,
/// it is meant to be used as metadata information.
/// </summary>
public readonly bool Required;
public DataFieldAttribute(string? tag = null, bool readOnly = false, int priority = 1, bool required = false, bool serverOnly = false, Type? customTypeSerializer = null) : base(readOnly, priority, serverOnly, customTypeSerializer)
{
Tag = tag;
Required = required;
}
public override string? ToString()
{
return Tag;
}
}
public abstract class DataFieldBaseAttribute : Attribute
{
public readonly int Priority;
public readonly Type? CustomTypeSerializer;
public readonly bool ReadOnly;
public readonly bool ServerOnly;
protected DataFieldBaseAttribute(bool readOnly = false, int priority = 1, bool serverOnly = false, Type? customTypeSerializer = null)
{
ReadOnly = readOnly;
Priority = priority;
ServerOnly = serverOnly;
CustomTypeSerializer = customTypeSerializer;
}
}
}