Forums

Attributes

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

Attributes

Postby K. Houwen » Sun Oct 17, 2010 3:50 pm

I've written an attribute with a property roles as Lists<of String>. When I want to use the attribute and assign something to roles, the compiler returns
Code: Select all
error: "Roles" is not a valid named attribute argument because it is not a valid attribute parameter type


Code of the Attribute
Code: Select all
   class AuthenticationAttribute inherits FilterAttribute
      has AttributeUsage(AttributeTargets.Class, allowMultiple = false, inherited = true), Serializable
      
      pro roles from var as List<of String>
      
      cue init()
         base.init(ExecuteWhen.BeforeAction, AuthenticationFilter)



Code where I use the attribute
Code: Select all
   class AdminController inherits ARSmartDispatcherController
      has AuthenticationAttribute(roles = ["admin"])


Maybe I made some stupid error I overlooked, I really need to get some sleep now :-) But could it be the compiler is looking for a property the C# way, with a capitalized first letter?
K. Houwen
 
Posts: 12

Re: Attributes

Postby Charles » Sun Oct 17, 2010 6:29 pm

This is a .NET thing. Attribute parameter has to be something fairly simply like a bool, char, float, int, string, System.Type, enum or array of those. See http://msdn.microsoft.com/en-us/library/aa664615(VS.71).aspx

Can you have Roles take an array or perhaps a single string which you split on space or some other punctuation?

Array literals in Cobra are basically like lists, but prefixed with @:
names = @['foo', 'bar']
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Attributes

Postby K. Houwen » Sun Oct 17, 2010 10:25 pm

Told you I was in need for some sleep :-)

Translated it wrong from c#, String[] is an array. Gonna give it a new try this evening. Thx for the reply.
K. Houwen
 
Posts: 12

Re: Attributes

Postby Charles » Sun Oct 17, 2010 11:21 pm

No problem. Where are you located? Just curious. I'm in Los Angeles / Pacific time zone.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Attributes

Postby K. Houwen » Mon Oct 18, 2010 12:00 am

Belgium, thats Europe between France and the Netherlands
K. Houwen
 
Posts: 12


Return to Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron