英文:
For the purposes of C# code generation in Sparx Enterprise Architect, is it possible to add class attributes, such as [Serializable]?
问题
我目前正在Sparx Enterprise Architect(EA)上设计一个将在C#和WPF中实现的系统。
我正在设计类,并想知道是否有办法在EA中为类添加.NET属性,例如[Serializable]
,以便在我从模型生成骨架C#代码时,这些属性会自动应用。
(这些是特定于.NET的类属性,在类定义之前定义。不要与类的属性混淆。)
英文:
I am currently working in Sparx Enterprise Architect (EA) on the design of a system that will be implemented in C# and WPF.
I am designing the classes and wondered whether there was any way to give a class .NET attributes such as [Serializable]
within EA so that when I generate the skeleton C# code from the model, these attributes are automatically applied.
(These are class attributes specific to .NET, defined just before the class definition. Not to be confused with attributes that are properties of the class)
答案1
得分: 3
我已经自己解决了。
答案是添加一个名为属性的标签,并赋予它值**[Serializable]**。
英文:
I've worked it out for myself.
The answer is to add a Tag named Attribute and give it the value [Serializable].
答案2
得分: -1
UML是与编程语言无关的。也就是说,您可以在不针对特定编程语言的情况下进行建模。为了在类中反映这一属性,最好考虑其目的,然后导致类似于Serializable
的编程属性。如果有一般性原因,您可以将其放入一个配置文件中,并对类进行建模,以便代码编写者或代码生成器可以识别它。
请注意,EA中的“标签值”是遗留的。以前的UML规范没有考虑配置文件,因此添加标签是自由的,这仍然存在于EA中。它应该被弃用,但Sparx似乎不太了解这个概念。因此,在测试目的时您可以使用它,但在进行严肃建模时,您需要考虑定义一个适用于您的建模领域的配置文件。
英文:
UML is programming language agnostic. That is, you model without targeting a specific programming language. In order to reflect that property in a class you are best off to think about the purpose which then leads to a programmatic attribute like Serializable
. If there is a general reason you can well put that in a profile and stereotype a class so it can be recognized by either a coder or a code generator.
Please note that the Tagged Value from EA is legacy. Former UML specs did not have profiles in mind so adding tags was a free form which still exists in EA. It should be deprecated but Sparx doesn't seem to know that concept in general. So you can use it for test purpose but when it's getting serious you need to think about defining a profile for your modeling domain.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论