使codeattributeargument代码生成使用:在C#中 [英] Make codeattributeargument code generation use a : in C#

查看:52
本文介绍了使codeattributeargument代码生成使用:在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码生成包含参数生成属性的代码。



代码如下:

I have code to generate code that includes generating attributes with parameters.

The code is e.g.:

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





但是如果我将此代码编译为C#代码,它会错误地使用等号而不是用于命名参数的冒号,例如





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

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





应该





which should be

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





我尝试过:



上面的代码......没有其他想法。



What I have tried:

The code as above... no other ideas.

推荐答案

我从来没有见过用作操作符的冒号属性(这是C#最新迭代中的另一个无用的新功能吗?),但等号IS绝对有效,假设其余的属性引用也有效,它应该编译没有问题。
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.


这篇关于使codeattributeargument代码生成使用:在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆