PC Review


Reply
Thread Tools Rate Thread

Browsable Attribute

 
 
Sean J Donovan
Guest
Posts: n/a
 
      9th Jul 2004
OK, I have a C# class. It's designable (ie. derives from Control), and
has a public property that has a GET method.

private string _stringA = "";

[System.ComponentModel.Browsable(false)]
public string StringA
{
get
{
// Force an exception.
Label l = null;
l.Text = "Hello";

return _stringA;
}
}


I don't want this property visible at design-time, so I add:

[System.ComponentModel.Browsable(false)]

In theory, whilst in design-mode, the GET method for my property should
never be called (let's also assume there's no progammatic code in the
constructor to call it, etc, either).

I test this by hard-coding an intentional exception into the GET method.
I then attach a 2nd VS.NET instance to the one I'm designing in, set
it trap C# exceptions, and let it continue.

Whenever the designer in the main instance hits an exception, the 2nd
instances of VS.NET will break, hopefully at the problem code.

If you create a simple usercontrol with this scenario, it'll never
exception. However, in a number of other cases it **does** exception.
I contend that it shouldn't, as it should NEVER be calling the GET
method. For example, you have UserControl1 in ClassLibrary1. If you
derive from that class, to UserControl2 in ClassLibrary2, you see the
2nd VS.NET always trap the exception, ie. the call to the GET method. Why?

Now, you can stop this, by adding the attribute:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

Now, I totally understand that by adding this, you're forcing the
code-serializer to NOT serialize the property. However, if you don't
have this property, and only have [Browsable(false)] it's totally
inconsistent as to whether the GET method is called or not.

So my question is, why does it call the GET method in some cases, and
not others?

This sounds unimportant, but in complex designable classes, it's a huge
issue.

Sean

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What happened to the Browsable Attribute??? Ole Microsoft Dot NET Compact Framework 7 10th Aug 2010 06:41 PM
propertygrid browsable attribute jan Microsoft Dot NET Framework Forms 1 2nd Sep 2008 10:52 AM
Browsable Attribute For Events Flix Microsoft C# .NET 4 6th Jun 2005 06:00 PM
Browsable protected attribute doesn't show in designer DS Microsoft C# .NET 0 3rd Jun 2005 06:26 AM
Browsable attribute =?Utf-8?B?QmVlZWVlZWVlZWVlZXZlcw==?= Microsoft VB .NET 1 30th Jul 2004 10:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.