From e14537074e9d50196bd4ddc5c312887d3da0450c Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 18 Feb 2025 07:21:40 -0500 Subject: [PATCH] Add ICloneable support to ComponentNetworkGenerator (#5656) --- .../ComponentNetworkGenerator.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs b/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs index b19ab4a25..27862aaf0 100644 --- a/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs +++ b/Robust.Shared.CompNetworkGenerator/ComponentNetworkGenerator.cs @@ -746,7 +746,17 @@ public partial class {componentName}{deltaInterface} private static bool IsCloneType(ITypeSymbol type) { - if (type is not INamedTypeSymbol named || !named.IsGenericType) + if (type is not INamedTypeSymbol named) + { + return false; + } + + if (ImplementsInterface(named, nameof(ICloneable))) + { + return true; + } + + if (!named.IsGenericType) { return false; } @@ -758,5 +768,18 @@ public partial class {componentName}{deltaInterface} _ => false }; } + + private static bool ImplementsInterface(ITypeSymbol type, string interfaceName) + { + foreach (var interfaceType in type.AllInterfaces) + { + if (interfaceType.ToDisplayString().Contains(interfaceName)) + { + return true; + } + } + + return false; + } } }