📜 ⬆️ ⬇️

Does C # need a “state”?

Guys, this is an invitation to a constructive discussion rather than an article. Faced with the fact that in C # there is no such thing as a “state”, or rather, there is no built-in convenient opportunity to remember the state of a complex object at a certain moment, so that it can be easily compared, or are other objects of the same type in the same state? Below, I offer an example of how it might look.

Any custom class
class Test { [StateAtt(StateCompareOption.AnyButNotThis)] //  ,   public double somefiled; public double anothersomefiled; //      -      [StateAtt(StateCompareOption.ExactlyLikeThis)] //    public string StringProp { get; set; } public int IntProp { get; set; } //      -    public Test(string StringProp, int IntProp, double somefiled, double anothersomefield) { this.StringProp = StringProp; this.IntProp = IntProp; this.somefiled = somefiled; this.anothersomefiled = anothersomefield; } } 



 Test a1 = new Test("text", 1, 50.4251, 34); State<Test> state = State<Test>.CreateState(a1); Test a2 = new Test("text", 1, 50.4252, 34); state.IsInTheSameState(a2).ToString().ToConsole(); //  true 


Guys, I want to ask your opinion. Do you think such a tool would be useful in development?

')

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


All Articles