Figure 4. C# indexer Point this[int row, int column]
Part 5.Modeling events
A C# event is modeled as a UML property (either a UML attribute or an association end), along with a <<CSharp Event>> stereotype. The UML property should have the same name as its corresponding C# event. The type of the UML property should be a UML class with a <<CSharp Delegate>> stereotype. Modifiers for a C# event are available as Boolean stereotype properties. For example, abstract, virtual, extern, override, and other modifiers are available in the <<CSharp Event>> stereotype properties. The accessors stereotype property is set to true if the event has its accessors (add or remove); otherwise, it is set to false.
This example (Figure 5) uses the handleResize() delegate for an event named mouseDrag in the class DrawingSurface class. To do this:
1. Add a public UML attribute to the DrawingSurface class, and apply the <<CSharp Event>> stereotype.
2. Set the attribute's type to a UML class that represents the handleResize delegate.
3. Set the accessors stereotype property to true, thereby indicating that add and remove accessors will be specified.
Figure 5. C# public event for handleResize mouseDrag
Part 6.Modeling attributes
The C# language allows programmers to provide certain kinds of declarative information through attributes attached to program entities. These attributes are defined as attribute classes. Attribute classes can be modeled in a manner similar to any other class, and they have a generalization relationship with a System.Attribute. The attribute use with a specific entity is depicted as a stereotype property named attributes in the corresponding stereotype for the entity. For example, an attribute declared for a C# class can be set as a string in the attributes stereotype property in the <<CSharp Class >> stereotype.
For this example, you will model an attribute class called TestAttribute and its use (also see Figure 6 and Figure 7):
1. Create a UML class named TestAttribute.
2. From the Project Explorer, look for the System.Attribute class in the References section of an imported C# project, and drag it onto a diagram. (Importing a C# project is described in this article about using this Rational extension to visualize .NET applications.)
3. Drag the TestAttribute class onto the diagram also, and show a generalization relationship from TestAttribute to System.Attribute.
4. Apply the <<CSharp Class >> stereotype to TestAttribute.
5. Set the attributes stereotype property in the <<CSharp Class >> to [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)].
6. Now, to use this attribute on any of your classes, such as GraphicObject, apply the <<CSharp Class>> stereotype and set its attributes stereotype property to [TestAttribute].
Figure 6. C# TestAttribute attribute class representation
Figure 7. C# Attribute use for TestAttribute
The attributes property in various stereotypes is are used in a similar manner, including the properties for these stereotypes:
Part 8.Modeling namespace
A C# namespace is modeled as a UML package. All types in a namespace are modeled as UML types in the corresponding package. The package should be named without any special characters. As an example, a class called MyClass in a namespace called com.ibm should be modeled as a class in a package called ibm, which is nested in another UML
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>