hannasm
hannasm

Reputation: 2041

Copy Constructor Static Analysis Tool?

Is there any tooling out there that will let me tag a C# method / constructor as a copy-constructor and have it check that code for the obvious mistakes which can occur in a copy-constructor scneario?

Some obvious mistakes to check for:

There are probably other clever checks i haven't thought of.

I haven't found any tooling that has anything supporting this. Code Contracts seems like an obvious tool to have this, but i haven't found it if it does exist.

Outside of a static analysis tool, are there any other tricks to make sure copy-constructors stay up-to-date?

Upvotes: 2

Views: 125

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564741

Unit testing is probably your best tool here.

C# doesn't create copy constructors automatically, like C++ and some other languages. As such, this isn't typically the problem that it tends to be in C++.

In general, they tend to be far more rare in general in C# code than in many other languages. As such, I suspect that you'd be better off including this check in your unit testing of those types, as needed, since they'll only be in a few specific types.

Upvotes: 1

Related Questions