Skip to content

Commit

Permalink
#11 fix for "... and needs to be imported"
Browse files Browse the repository at this point in the history
  • Loading branch information
greuelpirat committed Jul 20, 2019
1 parent f5d84f7 commit 4ad84af
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
5 changes: 4 additions & 1 deletion AnotherAssembly/AnotherAssembly.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46;netcoreapp2.2</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp2.2</TargetFrameworks>
<DisableFody>true</DisableFody>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DeepCopy\DeepCopy.csproj" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions AnotherAssembly/DeepCopyClassFromAnotherAssembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using DeepCopy;

namespace AnotherAssembly
{
[AddDeepCopyConstructor]
public class DeepCopyClassFromAnotherAssembly
{
public string Text { get; set; }
}
}
6 changes: 6 additions & 0 deletions AssemblyToProcess/ClassUsingOtherAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public class ClassUsingOtherAssembly
{
public ClassFromAnotherAssembly Property { get; set; }
}

[AddDeepCopyConstructor]
public class ClassUsingOtherDeepCopyAssembly
{
public DeepCopyClassFromAnotherAssembly Property { get; set; }
}
}
2 changes: 1 addition & 1 deletion DeepCopy.Fody/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private bool IsCopyConstructorAvailable(TypeReference type, out MethodReference

if (resolved.AnyAttribute(AddDeepCopyConstructorAttribute))
{
constructor = NewConstructor(type, type);
constructor = ModuleDefinition.ImportReference(NewConstructor(type, type));
return true;
}

Expand Down
23 changes: 23 additions & 0 deletions Tests/CopyOtherAssembly.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using AssemblyToProcess;
using Xunit;

Expand All @@ -14,5 +15,27 @@ public void TestClassUsingOtherAssembly()
var copy = Activator.CreateInstance(type, instance);
Assert.NotSame(instance, copy);
}

[Fact]
public void TestClassUsingOtherDeepCopyAssembly()
{
var type = GetTestType(typeof(ClassUsingOtherDeepCopyAssembly));
var instance = Activator.CreateInstance(type);
try
{
Activator.CreateInstance(type, instance);
Assert.True(false);
}
catch (TargetInvocationException exception)
{
Assert.True(exception.InnerException is MissingMethodException);
Assert.Contains("Void AnotherAssembly.DeepCopyClassFromAnotherAssembly..ctor(AnotherAssembly.DeepCopyClassFromAnotherAssembly)", exception.InnerException.Message);

}
catch
{
Assert.True(false);
}
}
}
}

0 comments on commit 4ad84af

Please sign in to comment.