How to determine a mutation in a C # function?

I read articles on how to program in a functional (e.g. F #) style in C #, for example, writing out loops for recursion and always returning a copy of a value / object instead of returning the same variable with a new state.

For example, what code checks should I track? Is there a way to find out if a BCL class method causes a mutation?

+3
source share
4 answers

Here are two things to help you find variables and fields whose values ​​are changing. Of course, interoperability is harder than that (for example, they won’t find calls to add to the collection), but depending on what you are looking for, they may be useful.

+2

NDepend , . , (.. ), ( ). : .

, , MyNamespace.ImmutableAttribute , .

[Immutable]class MyImmutableClass {...}

, , , LINQ (CQLinq) :

warnif count > 0 
from t in Application.Types
where !t.IsImmutable && t.HasAttribute("MyNamespace.ImmutableAttribute")
select t

// ​​ NDepend: :

+4

, # . , , .

Reflector ( , ), , - , , , , , .

, NDepend, - , .

, , . , , .

+1

, - . , - , , , .

, - , , . , .

0
source

Source: https://habr.com/ru/post/1707415/


All Articles