DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Delegate to properties

  1. #1
    Rune Bivrin Guest

    Delegate to properties


    I'm trying to write a small utility function to get the date from a text box
    into a database column, but set the column to NULL if the textbox is blank.
    The NULL part is easy, using a delegate to the SetXXXNull method.
    Getting the value into the property is harder. I can't seem to pass the property
    to an [out] or [ref] parameter, and I don't understand how to declare a delegate
    to the set_xxx property accessor.

    Am I attempting the impossible, or is it just the documentation that fails?

    Rune Bivrin

  2. #2
    GJ Guest

    Re: Delegate to properties


    Not exactly sure what you're trying to do, but I'll do my best:

    You can't pass a property as [out] or [ref] because it does not occupy a
    memory address, (at least if it is implemented like a property is in C++),
    because it is a type of macro that is substituted at compile time.

    Anyways, if I understand what you are trying to do, just subscribe to the
    TextChanged event of the TextBox.

  3. #3
    Rune Bivrin Guest

    Re: Delegate to properties


    "GJ" <star_screamer@hotmail.com> wrote:
    >
    >Not exactly sure what you're trying to do, but I'll do my best:
    >
    >You can't pass a property as [out] or [ref] because it does not occupy a
    >memory address, (at least if it is implemented like a property is in C++),
    >because it is a type of macro that is substituted at compile time.
    >
    >Anyways, if I understand what you are trying to do, just subscribe to the
    >TextChanged event of the TextBox.


    Well, I know why (in every painstaking technical detail) it doesn't work
    with ref-ed properties.
    I wanted to create a utility function to decode the value of any textbox
    and feed it to a column in a typed dataset. The trouble is this:
    Setting a column to a non-null value means setting a property, whereas setting
    it to a NULL value (DBNull, actually) means calling a separate property.
    That's why I wanted to pass the Set accessor and SetXXXNull method using
    delegates. As it stands, that won't work, so I had to do it another way instead.
    Mucky, but workable.
    Anyway, this is one reason properties are less useful than necessary. I can't
    see a technical reason for C# to disallow the creation of delegates to property
    accessors. The rationale might be that a delgate would create a difference
    between a field and a property, but that difference exists anyway, doesn't
    it? Otherwise, I would have been able to ref' the property, wouldn't you
    think?

    Thanks anyway,
    Rune Bivrin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center