Add ICloneable support to ComponentNetworkGenerator (#5656)

This commit is contained in:
Tayrtahn
2025-02-18 07:21:40 -05:00
committed by GitHub
parent af2d01981f
commit e14537074e

View File

@@ -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;
}
}
}