here is the problem, I am writing a small third-party library. In this library, I have a class like this
public class TestClass { public int TestField { get; private set; } public TestClass( ) { TestField = 1; } }
Then I have varialbe to make this class similar
public TestClass test = new TestClass( );
The problem I am facing is that our reflection is similar to this
PropertyInfo field = typeof( TestClass ).GetProperty( "TestField" ); field.SetValue( test, 2, null );
Programmers
can change the internal value of this class. it will be very bad, because it can destroy the library of holes. My question is what is the best way to protect my code form with such changes. I know that I can use some kind of bool flag, so the value can only be changed by one, but this is not a very good solution, is there a better one?
Best wishes,
Jordan
source share