diff --git a/Cloneable.Sample/ClassWithInheritance.cs b/Cloneable.Sample/ClassWithInheritance.cs
new file mode 100644
index 0000000..e50811e
--- /dev/null
+++ b/Cloneable.Sample/ClassWithInheritance.cs
@@ -0,0 +1,8 @@
+namespace Cloneable.Sample
+{
+ [Cloneable]
+ public partial class ClassWithInheritance : InheritedClass
+ {
+ public double C { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Cloneable.Sample/Cloneable.Sample.csproj b/Cloneable.Sample/Cloneable.Sample.csproj
index abee800..b8866c9 100644
--- a/Cloneable.Sample/Cloneable.Sample.csproj
+++ b/Cloneable.Sample/Cloneable.Sample.csproj
@@ -7,7 +7,9 @@
-
+
diff --git a/Cloneable.Sample/InheritedClass.cs b/Cloneable.Sample/InheritedClass.cs
new file mode 100644
index 0000000..dab1bf4
--- /dev/null
+++ b/Cloneable.Sample/InheritedClass.cs
@@ -0,0 +1,10 @@
+namespace Cloneable.Sample
+{
+ [Cloneable]
+ public partial class InheritedClass
+ {
+ public double A { get; set; }
+
+ public double B { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Cloneable.Sample/Program.cs b/Cloneable.Sample/Program.cs
index c398e26..31ccfd4 100644
--- a/Cloneable.Sample/Program.cs
+++ b/Cloneable.Sample/Program.cs
@@ -11,6 +11,7 @@ static void Main(string[] args)
DoSimpleExplicitClone();
DoDeepClone();
DoSafeDeepClone();
+ DoBaseClassClone();
}
static void DoSimpleClone()
@@ -79,5 +80,17 @@ static void DoSafeDeepClone()
Console.WriteLine("Is parents child copied: " + (clone.Child != parent.Child));
Console.WriteLine();
}
+
+ static void DoBaseClassClone()
+ {
+ var classWithInheritance = new ClassWithInheritance();
+
+ classWithInheritance.A = 2;
+
+ var clone = classWithInheritance.Clone();
+
+ Console.WriteLine(clone);
+ Console.WriteLine($"Clone A of Inherited Class:{clone.A}");
+ }
}
}
diff --git a/Cloneable/Cloneable.csproj b/Cloneable/Cloneable.csproj
index bdad948..6b63c21 100644
--- a/Cloneable/Cloneable.csproj
+++ b/Cloneable/Cloneable.csproj
@@ -4,6 +4,7 @@
Auto-generator of Clone method using C# Source Generator
netstandard2.0
latest
+ true
enable
false
https://github.com/mostmand/Cloneable
@@ -15,7 +16,8 @@
-
-
+
+
+
diff --git a/Cloneable/CloneableGenerator.cs b/Cloneable/CloneableGenerator.cs
index 850e708..44b316a 100644
--- a/Cloneable/CloneableGenerator.cs
+++ b/Cloneable/CloneableGenerator.cs
@@ -222,6 +222,16 @@ private IEnumerable GetCloneableProperties(ITypeSymbol classSym
var targetSymbolMembers = classSymbol.GetMembers().OfType()
.Where(x => x.SetMethod is not null &&
x.CanBeReferencedByName);
+
+ var baseTargetSymbolMembers = classSymbol.BaseType?.GetMembers().OfType()
+ .Where(x => x.SetMethod is not null &&
+ x.CanBeReferencedByName);
+
+ if (baseTargetSymbolMembers != null)
+ {
+ targetSymbolMembers = targetSymbolMembers.Concat(baseTargetSymbolMembers);
+ }
+
if (isExplicit)
{
return targetSymbolMembers.Where(x => x.HasAttribute(cloneAttribute!));