Skip to content

Commit

Permalink
Merge pull request #218 from ivsavchenko/bugfix/check-field-existence
Browse files Browse the repository at this point in the history
"Sequence contains no matching element" while trying to load recursively assembly that has c++ dependencies
  • Loading branch information
fgather authored Jul 12, 2023
2 parents b6f9473 + fb01c0c commit ebe55e5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
3 changes: 1 addition & 2 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
9 changes: 6 additions & 3 deletions ArchUnitNET/Loader/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ private ITypeInstance<IType> CreateTypeFromTypeReference(TypeReference typeRefer
return new TypeInstance<IType>(type);
}

if (typeDefinition.CustomAttributes.Any(att =>
att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName))
const string fixedElementField = "FixedElementField";

if (typeDefinition.CustomAttributes
.Any(att => att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName) &&
typeDefinition.Fields.Any(field => field.Name == fixedElementField))
{
var arrayType = typeDefinition.Fields.First(field => field.Name == "FixedElementField").FieldType;
var arrayType = typeDefinition.Fields.First(field => field.Name == fixedElementField).FieldType;
var arrayTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference(arrayType);
var dimensions = new List<int> { 1 };

Expand Down
13 changes: 13 additions & 0 deletions ArchUnitNETTests/ArchUnitNETTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@
</ItemGroup>

<ItemGroup>
<None Update="Dependencies\cpplib\CppDllTest.dll">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="Domain\PlantUml\zzz_test_version_with_errors.puml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Dependencies\cpplib\" />
</ItemGroup>

<ItemGroup>
<Reference Include="CppDllTest">
<HintPath>Dependencies\cpplib\CppDllTest.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
53 changes: 53 additions & 0 deletions ArchUnitNETTests/Dependencies/CppDependenciesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
// Copyright 2020 Pavel Fischer <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
//

using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Extensions;
using ArchUnitNET.Loader;
using Xunit;

namespace ArchUnitNETTests.Dependencies
{
public class CppDependenciesTests
{
private static readonly Architecture Architecture = new ArchLoader()
.LoadAssembliesRecursively(new[] { typeof(CppExampleClassUser).Assembly },
filterFunc => FilterResult.LoadAndContinue)
.Build();

[Fact]
public void CppClassUserFound()
{
var exampleCppUser = Architecture.GetClassOfType(typeof(CastClassA));
Assert.Contains(exampleCppUser, Architecture.Classes);
}
}

internal class CppExampleClassUser
{
CppExampleClass _cppExampleClass = new CppExampleClass();
}

/*
* C++/CLI code contains the next .h .cpp content
CppExampleClass.h
#pragma once
public ref class CppExampleClass
{
public:
void DoCall();
};
CppExampleClass.cpp
#include "pch.h"
#include "CppExampleClass.h"
void CppExampleClass::DoCall()
{
}
*/
}
Binary file not shown.

0 comments on commit ebe55e5

Please sign in to comment.