Files
RobustToolbox/Robust.Shared/Prototypes/IPrototype.cs
Pieter-Jan Briers 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

62 lines
1.8 KiB
C#

using System;
using Robust.Shared.Serialization.Manager.Attributes;
#if !ROBUST_ANALYZERS_TEST
using Robust.Shared.ViewVariables;
#endif
namespace Robust.Shared.Prototypes
{
/// <summary>
/// An IPrototype is a prototype that can be loaded from the global YAML prototypes.
/// </summary>
/// <remarks>
/// To use this, the prototype must be accessible through IoC with <see cref="IoCTargetAttribute"/>
/// and it must have a <see cref="PrototypeAttribute"/> to give it a type string.
/// </remarks>
public interface IPrototype
{
/// <summary>
/// An ID for this prototype instance.
/// If this is a duplicate, an error will be thrown.
/// </summary>
#if !ROBUST_ANALYZERS_TEST
[ViewVariables(VVAccess.ReadOnly)]
#endif
string ID { get; }
}
public interface IInheritingPrototype
{
string[]? Parents { get; }
bool Abstract { get; }
}
public sealed class IdDataFieldAttribute : DataFieldAttribute
{
public const string Name = "id";
public IdDataFieldAttribute(int priority = 1, Type? customTypeSerializer = null) :
base(Name, false, priority, true, false, customTypeSerializer)
{
}
}
public sealed class ParentDataFieldAttribute : DataFieldAttribute
{
public const string Name = "parent";
public ParentDataFieldAttribute(Type prototypeIdSerializer, int priority = 1) :
base(Name, false, priority, false, false, prototypeIdSerializer)
{
}
}
public sealed class AbstractDataFieldAttribute : DataFieldAttribute
{
public const string Name = "abstract";
public AbstractDataFieldAttribute(int priority = 1) :
base(Name, false, priority, false, false, null)
{
}
}
}