optional PropertyNameIsNull in Databindings PropertyName Changed pattern

  • Thread starter Thread starter Déjà-vu
  • Start date Start date
D

Déjà-vu

Hello everybody,

browsing code with the .Net reflector, I found out, that there is an
virtually undocumented feature in the PropertyName Changed pattern used,
when creating a custom control that supports databinding:

A boolean PropertyNameIsNull property, that - if available - will check
if the value of the control represents a NULL value.


public class Foo : Control
{
private string fFooString;

public event EventHandler ValueChanged;
public string Value
{
get { return fFooString; }
set
{
if (fFooString != value)
{
fFooString = value;
if (ValueChanged != null)
ValueChanged(this, new EventArgs());
}
}
}

public bool ValueIsNull
{
get { return fFooString == null; }
}
}


Is there any official documentation that relates to this fact?
Can this be used savely?
Why is it not documented?
Any ideas?

Tilman
 
Hello Déjà-vu,

Have u checked the IL code with ILDASM? What happens there.

Take into account that .NET reflector uses the "pattern matching" approach
and the result could be not 100% equal to your C# code

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


D> Hello everybody,
D>
D> browsing code with the .Net reflector, I found out, that there is an
D> virtually undocumented feature in the PropertyName Changed pattern
D> used, when creating a custom control that supports databinding:
D>
D> A boolean PropertyNameIsNull property, that - if available - will
D> check if the value of the control represents a NULL value.
D>
D> public class Foo : Control
D> {
D> private string fFooString;
D> public event EventHandler ValueChanged;
D> public string Value
D> {
D> get { return fFooString; }
D> set
D> {
D> if (fFooString != value)
D> {
D> fFooString = value;
D> if (ValueChanged != null)
D> ValueChanged(this, new EventArgs());
D> }
D> }
D> }
D> public bool ValueIsNull
D> {
D> get { return fFooString == null; }
D> }
D> }
D> Is there any official documentation that relates to this fact?
D> Can this be used savely?
D> Why is it not documented?
D> Any ideas?
D> Tilman
D>
 
Hello Michael,


Hello Déjà-vu,

Have u checked the IL code with ILDASM? What happens there.

Take into account that .NET reflector uses the "pattern matching" approach
and the result could be not 100% equal to your C# code

Even if .NET reflector does not spit out the original code, I think it
must be close enough. I would also assume, that if I compiled .NET
reflectors output, I would get pretty much the same IL code.
This is why I'm not really worrying about that argument.

What puzzles me, is that nobody seems to know anything about it...

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
Back
Top