Book a Demo

Author Topic: C# Custom Attributes!  (Read 6333 times)

Mikael

  • Guest
C# Custom Attributes!
« on: May 11, 2006, 10:12:20 am »
It seems that the reverse engineering of C# code store custom attributes becouse when I generate code they magically appear. I have looked and not found any way to augment anything but classes with custom attributes.

I would really like to have that feature since alot of nice things can be done by custom attributes.

Here is an example, first the orginal source:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
   public Service () {

       //Uncomment the following line if using designed components
       //InitializeComponent();
   }

   [WebMethod]
   public string HelloWorld() {
       return "Hello World";
   }
   
}

------------------------------

Then the source that EA generates for me:

///////////////////////////////////////////////////////////
//  Service.cs
//  Implementation of the Class Service
//  Generated by Enterprise Architect
//  Created on:      11-maj-2006 18:59:30
///////////////////////////////////////////////////////////




[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService {




~Service(){


}


public override void Dispose(){


}


public Service(){


}


[WebMethod]

public string HelloWorld(){


}

}//end Service

----------------------------

What I would like to is to edit the [WebMethod] custom attribute from with in EA.

Hope this will become a feature since C# heavly depends on custom attributes.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# Custom Attributes!
« Reply #1 on: May 11, 2006, 02:05:01 pm »
While we're on the subject, does anyone know how (or if) EA models the classes representing custom attributes? That is, the definition of the attribute itself, rather than the application of the attribute to another class.

This would be useful for modelling certain frameworks, as well as just creating your own attributes for recreational purposes, of course.   ;D
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# Custom Attributes!
« Reply #2 on: May 11, 2006, 03:04:27 pm »
Mikael, look at the tagged values for the "Attribute" tag.  Multiple attributes are separated by a ';'.

Midnight, my foggy early morning memory says that an attribute definition is just a class with a certain attribute applied.  You then have the relevant constructors.  In this case just use a normal class with the appropriate value of "Attribute".

Mikael

  • Guest
Re: C# Custom Attributes!
« Reply #3 on: May 15, 2006, 06:15:09 am »
I might be blind but there are not attribute tags for individual methods. If I remember correctly they are only available on class level.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# Custom Attributes!
« Reply #4 on: May 15, 2006, 06:41:11 am »
Are you referring to whether these exist in EA or in Visual Studio (C#)?
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# Custom Attributes!
« Reply #5 on: May 15, 2006, 03:29:34 pm »
To get the tagged values for any operation (and its parameters) in EA.  Open the tagged values window and select the operation

a) In the tree
b) On the diagram
c) In the Operations dialog.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# Custom Attributes!
« Reply #6 on: May 15, 2006, 04:48:00 pm »
Please correct me if I'm wrong Simon, but I believe it is possible to add tags to each method (= operation in EA) and for each parameter (separately and individually).

I'm just clarifying what you've already said, but for some purposes this is a vital distinction.

David
« Last Edit: May 15, 2006, 04:49:27 pm by Midnight »
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# Custom Attributes!
« Reply #7 on: May 15, 2006, 05:14:09 pm »
Yes, that is correct.  So my post really should have read "To view the existring tagged values for each operation and its parameters, or to add new tags ..."

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: C# Custom Attributes!
« Reply #8 on: May 15, 2006, 05:49:48 pm »
Thanks Simon,

But... I did not mean to correct, only to augment. I think you answered the question as given. I just wanted to clarify (for myself as well as Avi et al) that the 'notes' concept within EA is comprehensive.

There's an ulterior motve here; unlike the hoards of supplicants plead for RTF notes, I'm waiting patiently for XML support. Then I (and Avi or course) can, given an XSLT template or two, do any number of things.

Of course, we'll be asking for a new scripting language at that point, that will allow us to directly translate our models into the new "Rule the World" function, but surely you are already planning to include this in version 7.x. In the meantime I'll consider an add-in...  ;D
No, you can't have it!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: C# Custom Attributes!
« Reply #9 on: May 15, 2006, 07:56:46 pm »
Quote
[size=13][SNIP][/size]
There's an ulterior motve here; unlike the hoards of supplicants plead for RTF notes, I'm waiting patiently for XML support. Then I (and Avi or course) can, given an XSLT template or two, do any number of things.
[size=13][SNIP][/size]
Dave,

I'm also interested in XML.  

Paolo

Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!