Click here to Skip to main content
15,905,877 members
Home / Discussions / C#
   

C#

 
GeneralPropertyGrid Pin
netJP12L19-Dec-07 4:27
netJP12L19-Dec-07 4:27 
GeneralRe: PropertyGrid Pin
TJoe19-Dec-07 5:30
TJoe19-Dec-07 5:30 
GeneralRe: PropertyGrid Pin
netJP12L19-Dec-07 5:37
netJP12L19-Dec-07 5:37 
AnswerRe: PropertyGrid Pin
TJoe19-Dec-07 6:05
TJoe19-Dec-07 6:05 
GeneralRe: PropertyGrid Pin
netJP12L19-Dec-07 6:58
netJP12L19-Dec-07 6:58 
AnswerRe: PropertyGrid Pin
TJoe20-Dec-07 3:00
TJoe20-Dec-07 3:00 
GeneralRe: PropertyGrid Pin
netJP12L20-Dec-07 5:26
netJP12L20-Dec-07 5:26 
GeneralRe: PropertyGrid Pin
TJoe20-Dec-07 5:59
TJoe20-Dec-07 5:59 
Let's take an example. Assume that I'm a company providing a class/control that you purchased (e.g. Microsoft), and I have the following class that I provide you (the developer):

public class SomeClass {
    private Int32 hiddenInt = 0;
    
    public Int32 SomeProperty {
        get {
            return this.hiddenInt;
        }
    }    
}


Now, I would compile this class and only provide you with the assembly. So in your code, you would only be able to see SomeProperty, because it's public. You cannot see hiddenInt, because it's private.

Also, let's assume you want to change hiddenInt (probably because changing it would result in some effect you desire, such as limiting the number of characters that can be entered into a text box). You can use Reflection to change this value, like so:

//...
using System.Reflection;
 
//...
SomeClass c = new SomeClass();
Type t = typeof(SomeClass);
FieldInfo fi = t.GetField("hiddenInt",
    BindingFlags.NonPublic | BindingFlags.Instance);
fi.SetValue(c, 1);
  
// c.SomeProperty will now return 1, NOT 0


So you build your application and everything works great. But now I update my class (with bug fixes or optimizations) and I change it to:

public class SomeClass {
    public Int32 SomeProperty {
        get {
            return 0;
        }
    }    
}


As you can see, I removed the field and simply hard-coded the 0 in the property. Since hiddenInt was not visible to consumers of my class, I am free to change or remove it. Now if you start to use my new class, then you application will be broken. Because I no longer have the hiddenInt field.

This is a simple example, where you could simply detect that the field is no longer there and ignore the "error". But in the case of the PropertyGrid, you are enforcing user input. So your users would see a change in functionality or usability, if you were to ignore the error.

Now, in the case of the article you linked to. The code uses the "internal" name of the grid's control. This name can be changed at any time by MS.

Basically, if you start using things that are not publically visible (either public or protected in C# speak), then you can run into problems.
Take care,
Tom

-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com

Generalhelp quick Pin
nta_388619-Dec-07 4:26
nta_388619-Dec-07 4:26 
GeneralRe: help quick Pin
m@u19-Dec-07 4:45
m@u19-Dec-07 4:45 
GeneralRe: help quick Pin
Paul Conrad24-Dec-07 19:43
professionalPaul Conrad24-Dec-07 19:43 
GeneralProblems with PAINT program Pin
Luc Pattyn19-Dec-07 5:21
sitebuilderLuc Pattyn19-Dec-07 5:21 
GeneralSession Pin
anupamwb19-Dec-07 3:38
anupamwb19-Dec-07 3:38 
GeneralRe: Session Pin
DotNetXenon19-Dec-07 9:57
DotNetXenon19-Dec-07 9:57 
GeneralRe: Session Pin
anupamwb20-Dec-07 3:02
anupamwb20-Dec-07 3:02 
GeneralGenerics - How to implement Compare Methods Pin
gunner_uk200019-Dec-07 2:27
gunner_uk200019-Dec-07 2:27 
GeneralRe: Generics - How to implement Compare Methods Pin
OsoreWatashi19-Dec-07 2:52
OsoreWatashi19-Dec-07 2:52 
GeneralRe: Generics - How to implement Compare Methods Pin
LongRange.Shooter19-Dec-07 11:18
LongRange.Shooter19-Dec-07 11:18 
QuestionCapturing messeges from other program Pin
OsoreWatashi19-Dec-07 2:14
OsoreWatashi19-Dec-07 2:14 
AnswerRe: Capturing messeges from other program Pin
TJoe20-Dec-07 3:11
TJoe20-Dec-07 3:11 
GeneralRe: Capturing messeges from other program Pin
OsoreWatashi28-Dec-07 3:45
OsoreWatashi28-Dec-07 3:45 
General[Message Deleted] Pin
eyeseetee19-Dec-07 1:02
eyeseetee19-Dec-07 1:02 
GeneralRe: strange problem with stored procedure Pin
Pete O'Hanlon19-Dec-07 1:18
mvePete O'Hanlon19-Dec-07 1:18 
GeneralRe: Deleted Message Pin
Paul Conrad24-Dec-07 19:44
professionalPaul Conrad24-Dec-07 19:44 
QuestionC#:Doubt in event handler? Pin
kssknov19-Dec-07 0:14
kssknov19-Dec-07 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.