Results 1 to 25 of 25

Thread: [RESOLVED] Default Property Values

Threaded View

  1. #10
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Default Property Values

    Quote Originally Posted by wolfpackmars2 View Post
    What would be the use for the DefaultValue property, aside from where a property grid may be used?
    Not much really, except if you created a UserControl / custom control / component that you rely on heavily and want to add some user-friendliness to it. If 'where a property grid may be used' you mean dropping a PropertyGrid control on your form, then I'm not even sure if the DefaultValue attribute can be used, because the PropertyGrid does not show the context menu. I suppose you can add your own context menu, but then I'm not sure how to call the functionality that the Reset feature usually provides.

    So basically it is just to make the design-time easier for your own custom controls.


    Quote Originally Posted by kleinma View Post
    So really the only time you need full properties in VS2010 now is when you need logic in your getter/setter, or if you need read only/write only properties.
    Can't you just use ReadOnly?
    vb.net Code:
    1. Public ReadOnly Property Value() As Integer
    Shouldn't that just create a read-only automated property?

    I think you do need to use full properties if you need different access modifiers on the getter and setter (or is that possible even with auto-implemented properties?).
    If you can't, then I must say I like C#'s way much better:
    csharp Code:
    1. // read-only:
    2. public int Value { get; }
    3.  
    4. // private set; public get:
    5. public int Value { get; private set; }



    That said, I'm not sure how it would be possible to implement this behavior for VB without breaking all formatting rules... Perhaps something like
    vb.net Code:
    1. Public Property Value() As Integer { Get, Private Set }
    2.  
    3. Public Property Value() As Integer With Get, Private Set
    4.  
    5. Public Property Value() As Integer With { Get, Private Set }
    6.  
    7. Public Property Value() As Integer
    8.    Get
    9.    Private Set
    10. End Property
    Meh?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width