Sunday, April 17, 2011

How do you model c# attributes in UML?

I want to model c# class attributes and variable attributes (not UML attributes) in UML and am not sure how to do it.

[AttributeForTheClass]
class SomeClass
{
    [AttributeForTheField]
    int SomeField;

    [AttributeForTheMethod]
    int SomeMethod(
     [AttributeForTheParameter]int someParam)
    {
     ...
    }
}

How do you model:

[AttributeForTheClass] and [AttributeForTheField] and [AttributeForTheMethod]

Currently we use Sparx Enterprise Architect.

I know that c# attributes are a c# language feature but I am not sure they are even defined in UML.

Anyone have a solution?

From stackoverflow
  • What happens when you reverse engineer some C# code which has attributes? Do you get stereotypes or tagged values?

    From a modelling view, they should be stereotypes and any parameters of the attributes should be tagged values, but it's easier to go with what the tool supports if it can.

  • EA imports attribtues as tagged values with the name "Attribute", and the text of the attributes, concatenated, as the value:

    [WebService(Namespace = "http://dataservice/")];[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)];[System.ComponentModel.ToolboxItem(false)]

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.