TNG / ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
Apache License 2.0
826 stars 55 forks source link

163 immutability checks #175

Closed grzegorzorwat closed 1 year ago

grzegorzorwat commented 1 year ago

PR resolves #163. Adds checks for init setter in properties and immutability in classes.

It works with init setters from C# 8 and records from C# 9, even with ArchUnitNET targieting .net standard 2.0, which only supports C# 7, because those features are only syntactic sugar.

I didn't want to include IsImmutable in Member. Instead, I wanted to add predicates that would check if Member is readonly or has an init setter, and I wanted to use that predicate on all classes' members to see if they are immutable at the class level. However, I couldn't figure out how to combine class and member predicates, so I ended up with IsImmutable in Member.

grzegorzorwat commented 1 year ago

I removed IsReadOnly property because it was merged after last release so it shouldn't be breaking change. If you think it should remain, please let me know and I will restore it and make it return value from new Writablity property. 

fgather commented 1 year ago

this looks good to me, thank you very much @grzegorzorwat