ArchUnitNET
ArchUnitNET copied to clipboard
Q: How do I create an instance of IType from System.Type?
Using a custom ICondition<Class> I'm writing a set of tests to validate a set of constructors in my library's layer.
I'm enumerating constructor's IType parameters, and I'd like to compare them vs expected System.Type(s) to make my test assertions. The IType has an .IsAssignableTo(IType) method, which I'd gladly use, however I'm not able to convert my System.Type(s) to an IType.
I'm it that to be somewhat difficult to do, and I haven't found anything in the docs yet. Can anybody explain how can this be achieved?
I'm asking myself the same question. Any tip to share, @alexanderlinne?
Ok, I found by some other people's example that you can do Architecture.GetClassOfType(typeof(YourClass)) or Architecture.GetInterfaceOfType(typeof(IYourInterface)) to get the instance that satisfies an IType interface for the lib methods.
I'd like to know if there's any better alternative, but this works.
Hope it helps.
Hi @mmisztal1980, @CesarD already gave the correct answer. There's also the more generic method Architecture.GetITypeOfType(typeof(YourType)), which is probably best suited for your case. Feel free to reopen if there are any further questions.