473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Once again, attributes for MC++ properties

In MC++ properties are syntactically created through member functions
declared with the __property keyword and using set_ and get_ naming
conventions. Given that a property is specified in this way, how does one
set an attribute for a property ? Does one have to precede both the set_XXX
and get_XXX __property declaration with the same attribute declaration, or
is preceding one or the other good enough to tell the MC++ compiler that the
given attribute needs to be set for the property as a whole ?
Nov 17 '05 #1
4 1498
Hi Edward,
In MC++ properties are syntactically created through member functions
declared with the __property keyword and using set_ and get_ naming
conventions. Given that a property is specified in this way, how does one
set an attribute for a property ? Does one have to precede both the set_XXX and get_XXX __property declaration with the same attribute declaration, or
is preceding one or the other good enough to tell the MC++ compiler that the given attribute needs to be set for the property as a whole ?


Putting it on either one should work. Actually, if you put it in both, the
resulting property metadata might end up associated with the same attribute
twice (easy to verify by using ILDASM).

Personally, I think I prefer putting it on the get_XXX...
--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2
Hi again,
Putting it on either one should work. Actually, if you put it in both, the
resulting property metadata might end up associated with the same attribute twice (easy to verify by using ILDASM).


Just to make this more complete: By default, an attribute applied to a
__property method will be applied to the property as a whole [1]. To get the
attribute to apply to the method, you have to precede it with "method:" like
this:

[ method: ComVisible(true) ]
__property int get_Val() { return 4; }
[1] I presume the compiler could possibly apply it by default to the method
if it's an attribute that does not apply to properties, but I doubt the
compiler actually checks this... haven't tried it, though...

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #3
Tomas Restrepo (MVP) wrote:
Hi again,
Putting it on either one should work. Actually, if you put it in
both, the resulting property metadata might end up associated with
the same attribute twice (easy to verify by using ILDASM).


Just to make this more complete: By default, an attribute applied to a
__property method will be applied to the property as a whole [1]. To
get the attribute to apply to the method, you have to precede it with
"method:" like this:

[ method: ComVisible(true) ]
__property int get_Val() { return 4; }
[1] I presume the compiler could possibly apply it by default to the
method if it's an attribute that does not apply to properties, but I
doubt the compiler actually checks this... haven't tried it, though...


Thanks, that is the information I need. It does seem that this information,
about setting attributes on properties in C++, should be somewhere in the
MSDN docs for MC++, but I didn't find it anywhere there. Even more amazing,
it's not in Grimes' book <g> . I guess the documenters just assumed that one
would figure out that setting an attribute before a property get_ or set_
would set the attribute on the property as a whole.
Nov 17 '05 #4
Hi Edward,
Thanks, that is the information I need. It does seem that this information, about setting attributes on properties in C++, should be somewhere in the
MSDN docs for MC++, but I didn't find it anywhere there. Even more amazing, it's not in Grimes' book <g> . I guess the documenters just assumed that one would figure out that setting an attribute before a property get_ or set_
would set the attribute on the property as a whole.


I agree the MC++ docs do left out some things, which is rather annoying.
Fortunately, for the new CLI binding for C++ coming with whidbey (aka the
new MC++ dialect), things should be much better since we now have a much
more extensive, much more formal language specification (and the language
itself feels far more natural).

FWIW, I've added this little bit of information to my small MC++ faq
(http://www.winterdom.com/mcppfaq)... perhaps someone else might find it
useful.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Axel Dahmen | last post by:
I try to combine properties of several classes. This is done by assigning a space separated list of class definitions to an element. However, IE shows a kind of preference when choosing the right...
5
by: Martin | last post by:
Hi All, I'm trying to get at the data in a variable marked with my custom attribute. I'm not entirely sure where to begin. I've created my attribute class which is okay but at runtime I want to...
8
by: Roy Chastain | last post by:
I have tried this on a couple of occasions and each time the resulting program goes into a loop and eventually gets a stack overflow. public __gc BaseClass { __property virtual int get_IntValue...
3
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
0
by: NeoGeo | last post by:
Hello Can someone plz tell me why this doesn't work CategoryAttribute("MyCategory") Description("Custom Property Description." public: __property bool get_MyProp() public: __property...
2
by: P4trykx | last post by:
Hello I'm want to add some custom attributes to WebControls using WebControl.Attributes.Add("abc","234"); So the html output will look like this, <input type="hidden" abc="123" /etc. I know...
10
by: Joe Kovac | last post by:
Hi! I have a class with many bool attributes. Now I want to set them all at once to true or false, without forgetting one or the other. Any easy way to do that? (e.g. using reflection) ...
5
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.