Page 1 of 1

Attributes

PostPosted: Sun Oct 17, 2010 3:50 pm
by K. Houwen
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?

Re: Attributes

PostPosted: Sun Oct 17, 2010 6:29 pm
by Charles
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']

Re: Attributes

PostPosted: Sun Oct 17, 2010 10:25 pm
by K. Houwen
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.

Re: Attributes

PostPosted: Sun Oct 17, 2010 11:21 pm
by Charles
No problem. Where are you located? Just curious. I'm in Los Angeles / Pacific time zone.

Re: Attributes

PostPosted: Mon Oct 18, 2010 12:00 am
by K. Houwen
Belgium, thats Europe between France and the Netherlands