User Defined Attributes
Walter Bright
newshound2 at digitalmars.com
Tue Nov 6 09:34:08 PST 2012
On 11/6/2012 9:26 AM, Adam D. Ruppe wrote:
> On Tuesday, 6 November 2012 at 17:16:34 UTC, Adam D. Ruppe wrote:
>> [ExternalName("log-in")] /* we can do this now */
>> void logIn([ExternalName("user-id")] string userId)
>
>
> BTW we could conceivably do:
>
> [ExternalName("log-in"),
> ParameterAttribute!("userId")(ExternalName("user-id")]
> void logIn(string userId) {}
>
>
> Where the ParameterAttribute simply matches up the param by name or by position
> (if you pass an int instead of string) and puts the other argument in that map.
>
> When you scan the function for attributes, you keep your eye open for that
> ParameterAttribute thingy and match it up in the library.
>
>
> So if it is too painful to put it in the compiler, we could make it work in the
> library.
That looks like it can work. It's an interesting idea.
Other possibilities are:
1. Use a naming convention for the parameters, and then have an attribute for
the function that more or less means that the function follows that naming
convention. Naming conventions are often used in systems that don't have UDAs.
2. Use a user-defined wrapper type for the parameter. Then query for that type.
More information about the Digitalmars-d-announce
mailing list