Forums

[return:AttributeName]

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

[return:AttributeName]

Postby gauthier » Mon Jun 01, 2009 4:41 pm

Is there a way to do like c#:

Code: Select all
[return:AttributeName]
public object MethodName(){
 return null;
}
gauthier
 
Posts: 116

Re: [return:AttributeName]

Postby Charles » Mon Jun 01, 2009 4:53 pm

No, I guess there isn't. What do you think the syntax should be? Here are the current test cases:

<workspace>/Tests/320-misc-two/800-attributes

Although the source will look better in your local editor with syntax highlighting.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: [return:AttributeName]

Postby gauthier » Mon Jun 01, 2009 5:21 pm

it could be

def methodName as dynamic
has return(AttributeName(someValue="value")), Another(withAnotherValue="another one")
return 1


or anyother idea that looks better?

also, I'm in need for attribute on method parameters:
Code: Select all
void MethodName([AttributeName]object argument){}


could be
def methodName(argument has AttributeName as Object)
pass
gauthier
 
Posts: 116

Re: [return:AttributeName]

Postby Charles » Mon Jun 01, 2009 7:13 pm

Can you provide some actual attribute names you will be using for return and parameter attributes? I just want to see some concrete examples from your own use.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: [return:AttributeName]

Postby gauthier » Tue Jun 02, 2009 1:25 pm

JSONReturnBinder :
http://hammett.castleproject.org/?p=247

and DataBind :
http://www.castleproject.org/monorail/d ... l#databind

both from MonoRail MVC framework
gauthier
 
Posts: 116

Re: [return:AttributeName]

Postby Charles » Tue Jun 02, 2009 9:00 pm

Thanks. For parameters, I'm thinking:
use Castle.MonoRail.Framework

class ProductController inherits SmartDispatcherController

def create(prod as Product has DataBind('product'))
pass
which follows the same format as methods where "has Attribute" follows "as Type".

For return attributes I was thinking of just using the "return" keyword as a prefix:
class Foo

def getStates(countryCode as String) as State[]
has return JSONReturnBinder
return stateRepository.fetchAllByCountry(Country(countryCode))

Thoughts? Feelings?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: [return:AttributeName]

Postby gauthier » Wed Jun 03, 2009 1:01 pm

Chuck,

the only inconsistence with the parameter attribute is that the "has AttributeName" occurs somewhat after the parameter name to which it is attached,

but you are right that this is consistent with class and method declarations (however mostly occuring on another line) so it may be the right solution.

as for the second sample, that feel quite good to me

what others think about that?
gauthier
 
Posts: 116

Re: [return:AttributeName]

Postby Charles » Fri Jun 05, 2009 12:41 am

I have added the attributes for parameters in the Cobra repository. changeset:2102

Try it out and let me know if you have any problems.

I'll try to do the "return" attribute soon.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: [return:AttributeName]

Postby gauthier » Fri Jun 05, 2009 5:08 pm

Chuck, that's working all along for my purpose, thank you!
gauthier
 
Posts: 116

Re: [return:AttributeName]

Postby Charles » Fri Jun 05, 2009 8:28 pm

No problem. Now I've added support for the "return" target in changeset:2103. Try it out and let me know how it goes.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 40 guests