I have a property ggFileName defined like this:
private string _ggFileName = "";
public string ggFileName
{
get
{
return _ggFileName;
}
set
{
_ggFileName = value;
ReadXmlSchemaFromFile();
}
}
When assinging a value to ggFileName, the method ReadXmlSchemaFromFile(); is called. So far so good.
My problem is that when I assign the property ggFileName with the same value it already contains, nothing happens. The setter is not called until I assign it a different value.
I agree that in almost every case this is perfectly logical, but in my case it raises a problem. What if the file in ggFileName is changed outside my application ? Assigning the same file again to ggFileName does not calls my setter, so ReadXmlSchemaFromFile() is also not called. So now I have to set a dummy file to property ggFileName and than assign the same file again to ggFileName to get it working.
C# seems to be wanting to help me by not calling the setter when assigning the same value, how can I tell c# to stop helping me ?
I did not know that c# did this, in all my setters I have code like this: if (value != _myValue) { do setter logic here } I guess that I do not need to write that check anymore than ?
Just to make things more clear as people do not seem to understand my question. 1. My setter does get called, but only when assigning a different value 2. I do not want to use a method, because after setting the property I want some checks to be done and I do not want any other user of my class to be able to bypas that check. that is what properties are for, or not ? 3. The code that assignes a value I cannot post. It is a property of a custom control and it is called by the designer by editing the object inspector. Again, it works as long as I keep feeding it different values
thanks