Book a Demo

Author Topic: C# class, method and member variable attributes  (Read 4637 times)

d_p_robinson

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
C# class, method and member variable attributes
« on: March 23, 2007, 04:38:24 am »
C# Reverse engineering does not seem to generate any model artifacts for C# class, method and member variable attributes ([] notation).

For example, code:

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace TddSample
{
   [TestFixture]
   public class CalculatorTests
   {
       [Test]
       public void testAddZeroToZero ()
       {
           // Code for tests
       }
   }
}

'Test' and 'TestFixture' do not appear in the model. I have also imported the NUnit.Framework binary (exposes TestAttribute and TestFixtureAttribute classes) and this has no effect either.
David Robinson

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# class, method and member variable attribute
« Reply #1 on: March 25, 2007, 01:24:41 pm »
Have a look at the C# modeling conventions in the help.  (http://www.sparxsystems.com.au/EAUserGuide/index.html?csharp_conventions.htm)

They are in tagged values.

d_p_robinson

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: C# class, method and member variable attribute
« Reply #2 on: March 25, 2007, 11:20:59 pm »
I've checked the tagged values in the C# conventions page and these don't apply to C# attributes. In the example in my post a C# '[]' attribute can be applied to a class, interface, property, method or member variable. An attribute is an instance of a class attached as metadata to the item to which it refers. The C# page refers to modifiers such as const, delegate etc that are part of the C# language. C# attributes are user-defined extensions. I'm not sure how these would be expressed in EA as they're not really stereotype - for example they can take parameters.
David Robinson

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# class, method and member variable attribute
« Reply #3 on: March 26, 2007, 02:19:45 am »
Note that this also applies to VB.Net. Attributes can be applied to the same range of elements, and can take parameters. The concept is common across many .Net compilers.
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# class, method and member variable attribute
« Reply #4 on: March 26, 2007, 12:52:25 pm »
Quote
I've checked the tagged values in the C# conventions page and these don't apply to C# attributes. In the example in my post a C# '[]' attribute can be applied to a class, interface, property, method or member variable.

And as I said, in EA they are stored in tagged values.

On any class, interface, attribute, operation or parameter you can add a tagged value "Attribute" = "[TestFixture]" (or whatever your attributes are) and EA will generate them to code.

d_p_robinson

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: C# class, method and member variable attribute
« Reply #5 on: March 26, 2007, 10:54:31 pm »
Thanks. I hadn't spotted the Tagged Values window, I was only looking in the Class and Methods dialog boxes from where there is no reference to tagged values and in the class diagram where there is no indication of a tagged value being attached.
David Robinson