Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have code to generate code that includes generating attributes with parameters.

The code is e.g.:
VB.NET
Public Shared Function ParameterisedAttribute(ByVal AttributeName As String,
                                              ByVal parameters As IList(Of CodeAttributeArgument)
                                              ) As CodeAttributeDeclaration



    If parameters IsNot Nothing Then
        Return New CodeAttributeDeclaration(AttributeName, parameters.ToArray())
    Else
        Return New CodeAttributeDeclaration(AttributeName)
    End If


End Function


But if I codegen this to C# code it incorrectly uses an equals sign instead of a colon to name the parameter e.g.

C#
[CQRSAzure.EventSourcing.DomainNameAttribute(domainNameIn="Accounts")]


which should be

C#
[CQRSAzure.EventSourcing.DomainNameAttribute(domainNameIn:"Accounts")]


What I have tried:

The code as above... no other ideas.
Posted
Updated 26-Nov-16 0:49am

1 solution

I've never seen a colon used as an operator in an attribute (is this yet another useless new feature in the latest iteration of C#?), but the equal sign IS most definitely valid, and assuming the rest of the attribute reference is also valid, it should compile with no problems.
 
Share this answer
 
Comments
Duncan Edwards Jones 26-Nov-16 7:42am    
Bizarre but it definitely demands a colon in VS2015 / .NET 4.6.2
If I hover over it the parameter name is suggested but it puts the colon in.

Shall raise defect report with MS
#realJSOP 26-Nov-16 7:45am    
Try changing the targeted framework in the project using the attribute to 4.5 and see if it still wants a colon.
Duncan Edwards Jones 26-Nov-16 7:52am    
Yup - even 4.0 demands a colon for the named argument - https://msdn.microsoft.com/en-us/library/dd264739.aspx
murat_eraydin 3-Dec-16 13:30pm    
I'm trying to get in touch with you regarding an opportunity, can you somehow contact me? meraydin at karmasis com (I'm not sure if CP will allow this)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900