mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
Serv5 fixes (#6761)
This commit is contained in:
@@ -1140,21 +1140,7 @@ public class Generator : IIncrementalGenerator
|
||||
var nullableValue = isNullableValueType ? ".Value" : string.Empty;
|
||||
var nullNotAllowed = isClass && !isNullable;
|
||||
|
||||
if (CanBeCopiedByValue(field.Symbol, field.Type))
|
||||
{
|
||||
if (nullNotAllowed)
|
||||
{
|
||||
builder.AppendLine($$"""
|
||||
if (source.{{name}} == null)
|
||||
{
|
||||
throw new NullNotAllowedException();
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
builder.AppendLine($"{targetName} = source.{name};");
|
||||
}
|
||||
else if (field.CustomSerializer is { Serializer: var serializer, Type: var serializerType } &&
|
||||
if (field.CustomSerializer is { Serializer: var serializer, Type: var serializerType } &&
|
||||
((serializerType & Copier) != 0 || (serializerType & CopyCreator) != 0))
|
||||
{
|
||||
if (nullNotAllowed)
|
||||
@@ -1201,6 +1187,20 @@ public class Generator : IIncrementalGenerator
|
||||
if (isNullable || isNullableValueType)
|
||||
builder.AppendLine("}");
|
||||
}
|
||||
else if (CanBeCopiedByValue(field.Symbol, field.Type))
|
||||
{
|
||||
if (nullNotAllowed)
|
||||
{
|
||||
builder.AppendLine($$"""
|
||||
if (source.{{name}} == null)
|
||||
{
|
||||
throw new NullNotAllowedException();
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
builder.AppendLine($"{targetName} = source.{name};");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nullNotAllowed)
|
||||
|
||||
@@ -78,6 +78,12 @@ internal static class Types
|
||||
if (HasAttribute(type, CopyByRefNamespace))
|
||||
return true;
|
||||
|
||||
if (type is INamedTypeSymbol named &&
|
||||
HasAttribute(named.OriginalDefinition, CopyByRefNamespace))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.TypeKind == TypeKind.Enum)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
@@ -14,6 +15,7 @@ namespace Robust.Shared.Prototypes;
|
||||
/// </remarks>
|
||||
/// <remarks><seealso cref="EntProtoId"/> for an <see cref="EntityPrototype"/> alias.</remarks>
|
||||
[Serializable]
|
||||
[CopyByRef]
|
||||
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
|
||||
public readonly record struct ProtoId<T>(string Id) :
|
||||
IEquatable<string>,
|
||||
|
||||
+11
-1
@@ -21,7 +21,7 @@ namespace Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
/// to prevent time-offsets from being unintentionally saved to maps while mapping. If an entity must have an initial
|
||||
/// non-zero time, then that time should just be configured during map-init.
|
||||
/// </remarks>
|
||||
public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNode>
|
||||
public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNode>, ITypeCopyCreator<TimeSpan>
|
||||
{
|
||||
public TimeSpan Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
@@ -81,4 +81,14 @@ public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNo
|
||||
|
||||
return new ValueDataNode(value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public TimeSpan CreateCopy(
|
||||
ISerializationManager serializationManager,
|
||||
TimeSpan source,
|
||||
IDependencyCollection dependencies,
|
||||
SerializationHookContext hookCtx,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user